标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14225 Accepted Submission(s): 4945
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <cstdio> 5 #include <cmath> 6 7 using namespace std; 8 9 const int N=2E3+5; 10 int mmax; 11 int a[N],dp[N],posi; 12 int n,m; 13 14 void ZeroOnePack(int value ,int cost) 15 { 16 for ( int i = m - 5 ; i >= cost ; i-- ) 17 dp[i]=max(dp[i],dp[i-cost]+value); 18 19 } 20 21 int main() 22 { 23 while (scanf("%d",&n)!=EOF&&n) 24 { mmax = -1; 25 memset(dp,0,sizeof(dp)); 26 memset(a,0,sizeof(a)); 27 for ( int i = 1 ; i <= n ; i++) 28 scanf("%d",&a[i]); 29 for ( int i = 1 ; i <= n ; i++) 30 if ( a[i] > mmax ) 31 { 32 mmax=a[i]; 33 posi=i; 34 } 35 scanf("%d",&m); 36 if ( m< 5) {printf("%d\n",m);continue;} 37 38 39 for ( int i = 1 ; i <= n ; i++ ) 40 if ( i!=posi ) 41 ZeroOnePack(a[i],a[i]); 42 printf("%d\n",m-dp[m-5]-mmax); 43 } 44 return 0; 45 }
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4392425.html