题目传送门
解题思路:
题目里有,多重背包.
AC代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<map> 4 5 using namespace std; 6 7 int n,m,tot,f[22]; 8 string l; 9 map<string,int> p; 10 struct kkk{ 11 int a,b,c; 12 }e[101]; 13 14 int main() { 15 scanf("%d%d",&m,&n); 16 m = 21 - m; 17 for(int i = 1;i <= n; i++) { 18 int x,y,z; 19 scanf("%d%d%d",&x,&y,&z); 20 cin >> l; 21 if(!p.count(l)) p[l] = ++tot; 22 e[p[l]].a += x; 23 e[p[l]].b = y; 24 e[p[l]].c = z; 25 } 26 for(int i = 1;i <= tot; i++) 27 for(int j = m;j > 0; j--) { 28 int k = min(e[i].a,e[i].c); 29 f[j] = max(f[j],f[j-1] + e[i].b * k); 30 } 31 printf("%d",f[m]); 32 return 0; 33 }