HDU 2126 Buy the souvenirs
2015-04-11 18:39
369 查看
Buy the souvenirs
Time Limit: 1000msMemory Limit: 32768KB
This problem will be judged on HDU. Original ID: 2126
64-bit integer IO format: %I64d Java class name: Main
When the winter holiday comes, a lot of people will have a trip. Generally, there are a lot of souvenirs to sell, and sometimes the travelers will buy some ones with pleasure. Not only can they give the souvenirs to their friends and families as gifts, but also can the souvenirs leave them good recollections. All in all, the prices of souvenirs are not very dear, and the souvenirs are also very lovable and interesting. But the money the people have is under the control. They can’t buy a lot, but only a few. So after they admire all the souvenirs, they decide to buy some ones, and they have many combinations to select, but there are no two ones with the same kind in any combination. Now there is a blank written by the names and prices of the souvenirs, as a top coder all around the world, you should calculate how many selections you have, and any selection owns the most kinds of different souvenirs. For instance:
#include <bits/stdc++.h> using namespace std; const int maxn = 505; int dp[maxn][2],cost[35],T,n,m; int main(){ scanf("%d",&T); while(T--){ scanf("%d %d",&n,&m); for(int i = 0; i < n; ++i) scanf("%d",cost+i); memset(dp,0,sizeof dp); for(int i = 0; i <= m; ++i) dp[i][1] = 1; for(int i = 0; i < n; ++i){ for(int j = m; j >= cost[i]; --j) if(dp[j][0] < dp[j-cost[i]][0] + 1){ dp[j][0] = dp[j-cost[i]][0] + 1; dp[j][1] = dp[j-cost[i]][1]; }else if(dp[j][0] == dp[j-cost[i]][0] + 1) dp[j][1] += dp[j - cost[i]][1]; } if(dp[m][0]) printf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n",dp[m][1],dp[m][0]); else puts("Sorry, you can't buy anything."); } return 0; }
View Code
相关文章推荐
- hdu 2126 Buy the souvenirs(记录总方案数的01背包)
- hdu 2126 Buy the souvenirs(求方案数的背包)
- hdu2126——Buy the souvenirs——————【01背包记录物品最多时种数】
- hdu 2126 Buy the souvenirs (01背包输出方案数)
- Buy the souvenirs(hdu(2126)
- HDU-2126 Buy the souvenirs (DP)
- hdu 2126 Buy the souvenirs
- hdu 2126 Buy the souvenirs(求方案数)
- HDU 2126 Buy the souvenirs
- HDU 2126 Buy the souvenirs
- HDU 2126 Buy the souvenirs
- [HDU 2126] Buy the souvenirs (动态规划)
- HDU 2126 - Buy the souvenirs(01背包)
- hdu 2126 Buy the souvenirs(01背包求最大容量方法数)
- HDU 2126 Buy the souvenirs(DP:01背包)
- hdu 2126 Buy the souvenirs(0-1+最大方案数)
- HDU 2126 Buy the souvenirs (贪心&0-1背包最优解的个数)
- HDU 2126 (背包方法数) Buy the souvenirs
- Buy the souvenirs - HDU 2126 背包dp
- HDU - 2126 Buy the souvenirs