Piggy-bankTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 13792 Accepted Submission (s): 6981
Problem Descriptionbefore ACM can do anything, a budget must is prepared and the necessary financial support obtained. The main income for this action comes from irreversibly Bound money (IBM). The idea behind are simple. Whenever some ACM member have any small money, he takes all the coins and throws them into a piggy-bank. You know it is irreversible and the coins cannot be removed without breaking the pig. After a sufficiently long time, there should is enough cash in the Piggy-bank to pay everything that needs to be paid.
But there was a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might the "the pig into Pieces" only "find out" that there are not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility was to weigh the piggy-bank, and try to guess what many coins is inside. Assume that we is able to determine the weight of the pig exactly and so we know the weights of all coins of a given CU Rrency. Then there are some minimum amount of money in the Piggy-bank so we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the Piggy-bank. We need your help. No more prematurely broken pigs!
Inputthe input consists of T test cases. The number of them (T) is given in the first line of the input file. Each test case is begins with a line containing the integers E and F. They indicate the weight of an empty pig and of the pig filled with coins. Both weights is given in grams. No Pig would weigh more than ten kg, that means 1 <= E <= F <= 10000. On the second line of all test case, there is a integer number N (1 <= n <=) that gives the number of various Coins used in the given currency. Following this is exactly N lines, each specifying one coin type. These lines contain, integers each, pand w (1 <= P <= 50000, 1 <= w <=10000). P is the value of the coin in monetary units, and W is it's weight in grams.
Outputprint exactly one line of output for each test case. The line must contain the sentence "The minimum amount of money in the Piggy-bank are X." where x is the minimum amount of Money that can is achieved using coins with the given total weight. If the weight cannot was reached exactly, print a line "This is impossible."
Sample Input
310 11021 130 5010 11021 150 301 6210 320 4
Sample Output
The minimum amount of money in the Piggy-bank are 60.The minimum amount of money in the Piggy-bank are 100.This is Impossibl E.
Sourcecentral Europe 1999
Recommendeddy | We have carefully selected several similar problems for you:2191 1059 1074 1024 1160
Test instructions
have T Group data
The first behavior of each group of data e,f,f-e is the capacity of the backpack
Next there are n kinds of coins known to their value p[i], and the weight w[i],
When filling a backpack, the minimum value of the coin is combined.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib> #include <set> #include <queue> #include <stack > #include <vector> #include <map> #define N 55500#define Mod 10000007#define Lson l,mid,idx<<1# Define Rson mid+1,r,idx<<1|1#define LC idx<<1#define RC Idx<<1|1const Double EPS = 1e-11;const double PI = ACOs ( -1.0);//const double E = 2.718281828;typedef long long ll;const int INF = 100000010;using namespace Std;int n;i NT E,f;int p[n],w[n];int dp[n];int main () {int t; cin>>t; while (t--) {scanf ("%d%d", &e,&f); E=F-E; scanf ("%d", &n); for (int i=0; i<n; i++) scanf ("%d%d", &p[i],&w[i]); Fill (Dp,dp+n,inf); dp[0]=0; for (int i=0, i<n; i++) {for (int j=w[i]; j<=e; j + +) Dp[j]=min (Dp[j],dp[j-w[i]]+p[i]); } IF (dp[e]==inf) printf ("This is impossible.\n"); else printf ("The minimum amount of money on the Piggy-bank is%d.\n", dp[e]); } return 0;}
HDU 1114 Piggy-bank (full backpack)