zoukankan      html  css  js  c++  java
  • 称砝码

    现有一组砝码,重量互不相等,分别为m1、m2……mn;他们可取的最大数量分别为x1、x2……xn。现在要用这些砝码去称物体的重量,问能称出多少中不同的重量。

     1 import java.util.HashSet;
     2 import java.util.Scanner;
     3 import java.util.Set;
     4 
     5 
     6 public class Main {
     7     
     8     public static void main(String[] args) throws Exception  
     9     {
    10         Scanner scanner=new Scanner(System.in);
    11         int n=scanner.nextInt();
    12         int [] weights=new int[n];
    13         int [] count=new int[n];
    14         for(int i=0;i<n;i++)
    15         {
    16             weights[i]=scanner.nextInt();
    17         }
    18         for(int i=0;i<n;i++)
    19         {
    20             count[i]=scanner.nextInt();
    21         }
    22         Set<Integer> set=new HashSet<Integer>();
    23         set.add(0);
    24         for(int i=0;i<n;i++)
    25         {
    26             for(int j=0;j<count[i];j++)
    27             {
    28                 Object[] d=set.toArray();
    29                 for(int k=0;k<d.length;k++)
    30                 {
    31                     set.add((Integer)d[k]+weights[i]);
    32                 }
    33             }
    34         }
    35         System.out.println(set.size());
    36         scanner.close();
    37     }
    38 }
  • 相关阅读:
    servletContext
    解决Response输出时乱码
    servletConfig
    服务器和浏览器交互过程
    myeclipse配置
    servlet
    http协议
    配置虚拟主机
    配置主页
    开网站步骤
  • 原文地址:https://www.cnblogs.com/maydow/p/4779675.html
Copyright © 2011-2022 走看看