Test instructions: give you the value of n denominations, tell you the value of each face and the number of dollars, ask can make up the largest amount of money is not more than M.
Solution: Multiple backpacks. I think direct multi-pack Turn 01 should be t ... And I'm too lazy to do it in binary ... With the POJ1472 of the idea of doing a bit ...
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;bool dp[100005];int used[100005];struct node{int val, num;} Money[15];int Main () {int n, m; while (~SCANF ("%d%d", &m, &n)) {memset (DP, 0, sizeof DP); int ans = 0; for (int i = 1; I <= n; i++) scanf ("%d%d", &money[i].num, &money[i].val); Dp[0] = true; for (int i = 1; I <= n; i++) {memset (used, 0, sizeof used); for (int j = 1; j <= M; j + +) {if (!dp[j] && J >= Money[i].val && Dp[j-mon Ey[i].val] && Used[j-money[i].val] < Money[i].num) {ans = mAx (ans, j); DP[J] = true; USED[J] = Used[j-money[i].val] + 1; }}} printf ("%d\n", ans); } return 0;}
POJ 1276 Cash Machine