标签:nat target sts integer max strong contains any bank
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int v[12]={0,1,5,10,20,50,100,200,500,1000,2000}; int c[12],sum[12]; 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]=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
标签:nat target sts integer max strong contains any bank
原文地址:http://www.cnblogs.com/chen9510/p/7203129.html