标签:
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; int dp[1005],a[1005]; int main() { int n; while(scanf("%d",&n)!=EOF) { memset(dp,0,sizeof(dp)); memset(a,0,sizeof(a)); if(n==0) break; for(int i=1; i<=n; i++) scanf("%d",&a[i]); sort(a+1,a+1+n); int m; scanf("%d",&m); if(m<5) printf("%d\n",m); else { m=m-5; for(int i=1; i<=n-1; i++) for(int j=m; j>=a[i]; j--) dp[j]=max(dp[j],dp[j-a[i]]+a[i]); printf("%d\n",m+5-a[n]-dp[m]); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4409247.html