Allowance Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1039 Accepted: 444
Description
As a reward for record milk production, Farmer John has decided to start paying Bessie the cow a small weekly allowance. FJ has a set of coins in N (1 <= N <= 20) different denominations, where each denomination of coin evenly divides the next-larger denomination (e.g., 1 cent coins, 5 cent coins, 10 cent coins, and 50 cent coins).Using the given set of coins, he would like to pay Bessie at least some given amount of money C (1 <= C <= 100,000,000) every week.Please help him ompute the maximum number of weeks he can pay Bessie.Input
* Line 1: Two space-separated integers: N and COutput
* Line 1: A single integer that is the number of weeks Farmer John can pay Bessie at least C allowanceSample Input
3 6 10 1 1 100 5 120
Sample Output
111
#include#include #include #include #include using namespace std; int res; int need[25]; struct node { int val; int num; }nod[25]; int cmp(node p1,node p2) { if(p1.val>=p2.val) return 1; return 0; } int main() { int n,money,i,j,t,tmp; while(cin>>n>>money) { for(i=0;i =money面額的 { if(nod[i].val =t;i--) if(nod[i].val>=rest&&(nod[i].num-need[i])) { need[i]++; rest=0; break; } if(rest) break; } int ans=1e9; for(i=t;i