首页 > 代码库 > 【水】noip1996提高组 砝码称重

【水】noip1996提高组 砝码称重

A1104. 砝码称重

试题来源

  NOIP1996 提高组

问题描述

  设有1g、2g、3g、5g、10g、20g的砝码各若干枚(其总重<=1000)

输入格式

  a1 a2 a3 a4 a5 a6
  (表示1g砝码有a1个,2g砝码有a2个,…,20g砝码有a6个)

输出格式

  Total=N
  (N表示用这些砝码能称出的不同重量的个数,但不包括一个砝码也不用的情况)

样例输入

1 1 0 0 0 0

样例输出

Total=3

数据规模和约定

  总重<=1000

思路

在清澄上面看到这么可爱的一道题,这么早的提高组,还想试试多简单……真是很简单……

代码

#include<iostream>#include<cstdlib>#include<cstdio>using namespace std;int main(){    bool s[20000]={0};    int a1,a2,a3,a4,a5,a6,sum,total;    cin>>a1>>a2>>a3>>a4>>a5>>a6;    total=0;    for (int a=0;a<=a1;a++)        for (int b=0;b<=a2;b++)            for (int c=0;c<=a3;c++)                for (int d=0;d<=a4;d++)                    for (int e=0;e<=a5;e++)                        for (int f=0;f<=a6;f++)                        {                            sum=a*1+b*2+c*3+d*5+e*10+f*20;                            if (s[sum]==false) {total++; s[sum]=true; }                        }    cout<<"Total="<<total<<endl;    return 0;}

结果

 

【水】noip1996提高组 砝码称重