标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 22829 Accepted Submission(s): 8000
1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 #include<vector> 8 #include<iomanip> 9 #include<queue> 10 using namespace std; 11 int dp[10002]; 12 int max(int x,int y) 13 { 14 return x>y?x:y; 15 } 16 int main() 17 { 18 int n,m,num[1005]; 19 while(cin>>n&&n) 20 { 21 memset(dp,0,sizeof(dp)); 22 int maxn=-1000000,imaxn; 23 for(int i=0;i<n;i++) 24 { 25 cin>>num[i]; 26 if(num[i]>maxn) 27 { 28 maxn=num[i]; 29 imaxn=i; 30 } 31 } 32 num[imaxn]=0; 33 cin>>m; 34 if(m<5) 35 { 36 cout<<m<<endl; 37 continue; 38 } 39 m=m-5; 40 for(int i=0;i<n;i++) 41 { 42 for(int j=m;j>=num[i];j--) 43 { 44 dp[j]=max(dp[j],dp[j-num[i]]+num[i]); 45 } 46 } 47 cout<<m+5-dp[m]-maxn<<endl; 48 } 49 return 0; 50 }
标签:
原文地址:http://www.cnblogs.com/--ZHIYUAN/p/5727345.html