标签:iss 模板 tar sam targe pre bottom ane 生活
题目链接:https://vjudge.net/problem/HDU-2191
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 35693 Accepted Submission(s): 15054
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int main() { int t, p[105], w[105], c[105], dp[105]; scanf("%d", &t); while (t--) { int n, m, count = 0; scanf("%d %d", &n, &m); for (int i = 0; i<m; i++) scanf("%d %d %d", &p[i], &w[i], &c[i]); memset(dp, 0, sizeof(dp)); int temp = 0; for (int i = 0; i<m; i++) { for (int j = n; j >= p[i]; j--) { for (int k = 1; k <= c[i]; k++) //枚举每个种类大米的个数 { if (j<k*p[i]) break; dp[j] = max(dp[j - k * p[i]] + k * w[i], dp[j]); } } } printf("%d\n", dp[n]); } return 0; }
hdu 2191 悼念512汶川大地震遇难同胞 【多重背包】(模板题)
标签:iss 模板 tar sam targe pre bottom ane 生活
原文地址:https://www.cnblogs.com/00isok/p/9047884.html