标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15507 Accepted Submission(s):
5358
#include<stdio.h> #include<string.h> #include<algorithm> #define MAX 1010 #define max(x,y)(x>y?x:y) using namespace std; bool cmp(int a,int b) { return a<b; } int s[MAX],dp[MAX]; int main() { int n,m,j,i,k,t,sum; while(scanf("%d",&n),n) { for(i=0;i<n;i++) scanf("%d",&s[i]); scanf("%d",&m); if(m<5) { printf("%d\n",m); continue; } memset(dp,0,sizeof(dp)); sum=m-5; sort(s,s+n); for(i=0;i<n-1;i++) { for(j=sum;j>=s[i];j--) { dp[j]=max(dp[j],dp[j-s[i]]+s[i]); } } printf("%d\n",m-dp[sum]-s[n-1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/tonghao/p/4609162.html