3 条题解

  • 0
    @ 2022-7-5 10:42:39

    枚什么举!dp大法好!

    #include <bits/stdc++.h>
    using namespace std;
    const int cnt[] = {0, 1, 2, 3, 5, 10, 20};
    bitset<2005> ans;
    int x;
    int main() {
    	ans[0] = 1;
    	for (int i = 1; i <= 6; i ++) {
    		cin >> x;
    		for (int j = 1; j <= x; j ++)
    			ans |= ans << cnt[i];
    	}
    	cout << ans.count() - 1 << '\n';
    	return 0;
    }
    
  • 0
    @ 2022-7-5 10:40:20

    【问题描述】

    设有1g,2g,3g,5g,10g,20g的砝码各若干枚(其总重≤1000g),,要求计算用这些砝码能称出的不同重量的个数,但不包括一个砝码也不用的情况。

    思路

    题目中已经明确仅有六个砝码,再看数据范围:总重≤1000g,则这道题可以用暴力枚举做,即O(x1x2x3x4x5*x6)的时间复杂度,再用一个桶装称出来的砝码重量

    代码

    #include <bits/stdc++.h>
    using namespace std;
    int s[10011]/*数组切记开的比10000大,否则全WA*/,k,x1,x2,x3,x4,x5,x6;
    int main()
    {
    	cin>>x1>>x2>>x3>>x4>>x5>>x6;
    	//注意枚举从0开始,因为可以不选当前砝码 
    	for(int a=0;a<=x1;a++)
           for(int b=0;b<=x2;b++)
              for(int c=0;c<=x3;c++)
                 for(int d=0;d<=x4;d++)
    			    for(int e=0;e<=x5;e++)
    				   for(int f=0;f<=x6;f++) 
    				   //六重暴力 
                          s[a*1+b*2+c*3+d*5+e*10+f*20]++;//乘积装进桶里 
    
        for(int i=1;i<=10000;i++)
           if(s[i]!=0) k++; 
           //桶处理 
        cout<<k;
    	return 0;
    }
    

    注意事项

    数组一定得开的比10000大,否则会WA 我是不会告诉你们我在这卡了半个小时的

    • -1
      @ 2022-6-1 19:21:20

      #include<bits/stdc++.h> using namespace std; long long a,b,c,d,e,f,q; bool p[1086]; int main () { cin>>a>>b>>c>>d>>e>>f; for(int i=0; i<=a; i++) for(int i2=0; i2<=b; i2++) for(int j=0; j<=c; j++) for(int j2=0; j2<=d; j2++) for(int k=0; k<=e; k++) for(int k2=0; k2<=f; k2++) p[i+i22+j3+j25+k10+k2*20]=1; for(int i=1; i<=1000; i++) if(p[i])q++; cout<<q; return 0; }

      • 1

      信息

      ID
      65
      时间
      1000ms
      内存
      256MiB
      难度
      4
      标签
      (无)
      递交数
      89
      已通过
      43
      上传者