http://acm.hdu.edu.cn/showproblem.php?pid=1114
Test instructions: The piggy bank can put some small money into it, but it doesn't know how much money is in it after a long time, unless you break it. Now given the weight of the empty jar and the maximum capacity, and then give the value and weight of each coin, we have to confirm the minimum amount of money in the jar without breaking it.
Idea: very close to life. There is no limit to the number of coins, so it is a complete backpack. The condition must be filled to find the minimum value, then the initialization becomes full (backpack ix) and Max becomes min. If the full-capacity DP value is not changed after the item has been traversed, the coins cannot form this capacity. Because of the data 10000, so there is no two-dimensional.
#include <stdio.h> #include <algorithm> #include <stdlib.h> #include <string.h> #include <
Iostream> using namespace std;
typedef long Long LL;
const int N = 10005;
const int INF = 0X3F3F3F3F;
int dp[n];
int main () {//Freopen ("In.txt", "R", stdin);
int T, V, N, EMP, fil;
int cost[n], weight[n];
scanf ("%d", &t);
while (t--) {scanf ("%d%d", &emp, &fil);
scanf ("%d", &n);//number of items for (int i = 1; I <= n; i++) scanf ("%d%d", &weight[i], &cost[i]);
V = fil-emp;
Dp[0] = 0;//filled for (int i = 1; I <= V; i++) dp[i] = INF; for (int i = 1, i <= N; i++) for (int j = cost[i]; j <= V; j + +) {Dp[j] = min (
DP[J], dp[j-cost[i]]+weight[i]);
}/* for (int i = 0; I <= V; i++) printf ("%d", dp[i]); printf ("\ n"); */if (dp[v] = = INF) printf ("This is impossible.\n ");
else printf ("The minimum amount of money on the Piggy-bank is%d.\n", dp[v]);
} return 0;
}