标签:style blog http color os io java ar for
1 50 5 10 1 2 3 2 1 1 2 3 2 1 50 0
-45 32
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 int n,m,p[1010],dp[1010]; 18 int main() { 19 while(scanf("%d",&n),n) { 20 memset(dp,0,sizeof(dp)); 21 for(int i = 1; i <= n; i++) scanf("%d",p+i); 22 scanf("%d",&m); 23 sort(p+1,p+n+1); 24 dp[0] = 0; 25 if(m < 5) {printf("%d\n",m);continue;} 26 for(int i = 1; i < n; i++){ 27 for(int j = m-5; j >= p[i]; j--) 28 dp[j] = max(dp[j],dp[j-p[i]] + p[i]); 29 } 30 printf("%d\n",m-dp[m-5]-p[n]); 31 } 32 return 0; 33 }
标签:style blog http color os io java ar for
原文地址:http://www.cnblogs.com/crackpotisback/p/3948145.html