题目链接:https://vjudge.net/contest/228640#problem/F
转载于:http://www.voidcn.com/article/p-mxcorksq-gh.html
题目大意:
给定N种钱,每种面值Ai,数量Ci,问可凑出的总价值中有多少种在(0,M]范围之间
#include <iostream> #include <cstring> #include <algorithm> using namespace std; int a[120], c[120]; int dp[100020], use[100020]; int main() { int n, m; while (scanf("%d%d", &n, &m) == 2 && n&&m) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); dp[0] = 1; int ans = 0; for (int i = 1; i <= n; i++) { memset(use, 0, sizeof(use)); for (int j = a[i]; j <= m; j++) { if (dp[j] == 0 && dp[j - a[i]] == 1 && use[j - a[i]]<c[i]) { dp[j] = 1; use[j] = use[j - a[i]] + 1; ans++; } } } printf("%d ", ans); } return 0; }
2018-05-22