标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22962 Accepted Submission(s): 8047
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7 int n,m; 8 int price[1050]; 9 int d[1050]; 10 while(cin>>n,n) 11 { 12 memset(d,0,sizeof(d)); 13 14 for(int i=1;i<=n;i++) 15 cin>>price[i]; 16 cin>>m; 17 sort(price+1,price+n+1); 18 if(m<5) 19 { 20 cout<<m<<endl; 21 } 22 else 23 { 24 m-=5; 25 for(int i=1;i<n;i++) 26 for(int j=m;j>=price[i];j--) 27 { 28 29 d[j]=max(d[j],d[j-price[i]]+price[i]); 30 } 31 32 cout<<m+5-d[m]-price[n]<<endl; 33 } 34 } 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/hellohacker/p/5745167.html