[Hdu5527] [5acm/ICPC Changchun station in Asia] Too Rich
Question and Answer:
I feel that I am really weak. I think that I am greedy and wrong. I didn't even think of the 20-50 special sentence.
Code:
(Almost the same as the one that gathers, ORZ)
#include#include#include#includeusing namespace std;int val[11]={0,1,5,10,20,50,100,200,500,1000,2000};int x,T,p,num[11],vis[11],use[11];int ans=-1;long long sum;int solve(){ memset(use,0,sizeof(use)); if (vis[5]>num[5] || vis[8]>num[8]) return 0; long long tmp=vis[5]*val[5]+vis[8]*val[8]; int tmpn=vis[5]+vis[8]; for (int i=1;i<=10;i++) { if (vis[i]==-1) { tmp+=num[i]*val[i]; tmpn+=num[i]; use[i]=num[i]; } else { use[i]=num[i]-vis[i]; if (use[i]%2==1) use[i]--; tmpn+=use[i]; tmp+=use[i]*val[i]; } if (tmp>=x) { long long chao=tmp-x; for (int j=i;j>=1;j--) { if (vis[j]==-1) { long long tui=min((long long)use[j],chao/val[j]); tmpn-=tui; chao-=tui*val[j]; } else { long long tui=min((long long)use[j],chao/val[j]); if (tui%2==1) tui--; tmpn-=tui; chao-=tui*val[j]; } if (chao==0) { ans=max(ans,tmpn); return 0; } } return 0; } }}int main(){ scanf("%d",&T); while(T--) { scanf("%d",&x); memset(vis,-1,sizeof(vis)); for (int i=1;i<=10;i++) { scanf("%d",&num[i]); sum+=num[i]*val[i]; } if (sum