标签:icp 注意 maximum ret ogr src play mem else
http://acm.hdu.edu.cn/showproblem.php?pid=5527
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2032 Accepted Submission(s): 529
1 #include <cstdio> 2 #include <cstring> 3 #include <string> 4 #include <cmath> 5 #include <iostream> 6 #include <algorithm> 7 #include <queue> 8 #include <stack> 9 #include <vector> 10 #include <set> 11 #include <map> 12 #define maxn 50010 13 #define lson l,mid,rt<<1 14 #define rson mid+1,r,rt<<1|1 15 const long long INF=0x3f3f3f3f3f3f3f3f; 16 using namespace std; 17 long long coin[] = {0,1, 5, 10, 20, 50, 100, 200, 500, 1000, 2000}; 18 long long a[12]; 19 long long ans; 20 21 void dfs(int pos,long long sum,long long num){ 22 if(sum==0){ 23 ans=min(ans,num); 24 return; 25 } 26 if(pos<1){ 27 return; 28 } 29 long long tmp=min(a[pos],sum/coin[pos]); 30 dfs(pos-1,sum-tmp*coin[pos],num+tmp); 31 if(tmp>0){//去掉一个硬币的情况 32 tmp--; 33 dfs(pos-1,sum-tmp*coin[pos],num+tmp); 34 } 35 } 36 37 int main(){ 38 int t; 39 scanf("%d",&t); 40 while(t--){ 41 int total=0; 42 long long sum=0; 43 for(int i=0;i<11;i++){ 44 scanf("%lld",&a[i]); 45 sum+=coin[i]*a[i]; 46 total+=a[i]; 47 } 48 total-=a[0];//a[0]表示p 49 if(sum<a[0]){ 50 puts("-1"); 51 continue; 52 } 53 sum-=a[0]; 54 ans=INF; 55 dfs(10,sum,0); 56 if(ans==INF){ 57 puts("-1"); 58 } 59 else{ 60 printf("%lld\n",total-ans); 61 } 62 } 63 }
标签:icp 注意 maximum ret ogr src play mem else
原文地址:https://www.cnblogs.com/Fighting-sh/p/9737269.html