标签:set php mem 表示 商品 nbsp arch end title
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28562 Accepted Submission(s): 9876
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int price[1010],dp[1010]; 6 int n; 7 while(scanf("%d",&n)&&n) 8 { 9 memset(price,0,sizeof(price)); 10 memset(dp,0,sizeof(dp)); 11 for(int i=1;i<=n;i++) 12 cin>>price[i]; 13 sort(price+1,price+1+n); 14 int MAXN=price[n]; 15 int res; 16 cin>>res; 17 if(res<5) 18 { 19 cout<<res<<endl; 20 continue; 21 } 22 res-=5; 23 for(int i=1;i<n;i++) 24 { 25 for(int j=res;j>=price[i];j--)//01背包主函数 26 { 27 dp[j]=max(dp[j],dp[j-price[i]]+price[i]); 28 } 29 } 30 printf("%d\n",res+5-dp[res]-MAXN); 31 } 32 return 0; 33 }
标签:set php mem 表示 商品 nbsp arch end title
原文地址:http://www.cnblogs.com/ECJTUACM-873284962/p/6819150.html