标签:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAX = 1100; int main() { int dp[MAX],w[MAX]; int n,m; while(~scanf("%d",&n)&&n){ memset(dp,0,sizeof(dp)); memset(w,0,sizeof(w)); for(int i = 1; i <= n ;i++) scanf("%d",&w[i]); scanf("%d",&m); sort(w+1,w+n+1); if(m < 5) { printf("%d\n",m); continue; } else { for(int i= 1; i <= n -1; i++){ for(int j = m - 5; j >= w[i]; j--){ dp[j] = max(dp[j],dp[j-w[i]]+w[i]); } } printf("%d\n",m - dp[m-5] - w[n]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4445421.html