标签:dp
#include<iostream> #include<memory.h> using namespace std; int max1(int a,int b) { return a>b?a:b; } int dp[10100]; int main() { int n,t,wi[10100],max,p,i,j,s; while(cin>>n) { if(n==0) { break; } max=-1; memset(wi,0,sizeof(wi)); s=0; p=0; for(i=0;i<n;i++) cin>>wi[i]; cin>>t; for(i=0;i<n;i++) { if(wi[i]>max) { max=wi[i]; p=i; } } wi[p]=0; memset(dp,0,sizeof(dp)); if(t<5) cout<<t<<endl; else { t=t-5; for(i=0;i<n;i++) { for(j=t;j>=wi[i];j--) { dp[j]=max1(dp[j],dp[j-wi[i]]+wi[i]); } } s=t+5-dp[t]-max; cout<<s<<endl; } } return 0; }
标签:dp
原文地址:http://blog.csdn.net/r_misaya/article/details/40515433