# HDU 5527---Too Rich（贪心+搜索）

Problem Description
You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker which costs

Input
The first line contains an integer

Output
For each test case, please output the maximum number of coins and/or banknotes he can pay for exactly

Sample Input
3
17 8 4 2 0 0 0 0 0 0 0
100 99 0 0 0 0 0 0 0 0 0
2015 9 8 7 6 5 4 3 2 1 0

Sample Output
9
-1
36

p=1020   0 0  0 49  1   0   0   0    1     0；

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int v={0,1,5,10,20,50,100,200,500,1000,2000};
int c,sum;
int p,ans;
void dfs(int i,int rest,int count)
{
if(rest<0) return ;
if(i==0) {
if(rest==0) ans=max(ans,count);
return ;
}
int tmp=max(0,rest-sum[i-1]);
int cn=tmp/v[i]+(tmp%v[i]!=0);
if(cn<=c[i])  dfs(i-1,rest-cn*v[i],count+cn);
cn++;
if(cn<=c[i])  dfs(i-1,rest-cn*v[i],count+cn);
}
int main()
{
///cout << "Hello world!" << endl;
int T; cin>>T;
while(T--)
{
scanf("%d",&p);
for(int i=1;i<=10;i++) scanf("%d",&c[i]);
sum=0;
for(int i=1;i<=10;i++) sum[i]=sum[i-1]+v[i]*c[i];
ans=-1;
dfs(10,p,0);
printf("%d\n",ans);
}
return 0;
}
///1020 0 0  0 49  1   0   0   0    1     0

posted @ 2017-07-18 22:01  茶飘香~  阅读(...)  评论(...编辑  收藏