码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 3033 I love sneakers!

时间:2015-04-22 20:09:56      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

I love sneakers!

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on HDU. Original ID: 3033
64-bit integer IO format: %I64d      Java class name: Main
After months of hard working, Iserlohn finally wins awesome amount of scholarship. As a great zealot of sneakers, he decides to spend all his money on them in a sneaker store.
技术分享

There are several brands of sneakers that Iserlohn wants to collect, such as Air Jordan and Nike Pro. And each brand has released various products. For the reason that Iserlohn is definitely a sneaker-mania, he desires to buy at least one product for each brand.
Although the fixed price of each product has been labeled, Iserlohn sets values for each of them based on his own tendency. With handsome but limited money, he wants to maximize the total value of the shoes he is going to buy. Obviously, as a collector, he won’t buy the same product twice.
Now, Iserlohn needs you to help him find the best solution of his problem, which means to maximize the total value of the products he can buy.
 

Input

Input contains multiple test cases. Each test case begins with three integers 1<=N<=100 representing the total number of products, 1 <= M<= 10000 the money Iserlohn gets, and 1<=K<=10 representing the sneaker brands. The following N lines each represents a product with three positive integers 1<=a<=k, b and c, 0<=b,c<100000, meaning the brand’s number it belongs, the labeled price, and the value of this product. Process to End Of File.
 

Output

For each test case, print an integer which is the maximum total value of the sneakers that Iserlohn purchases. Print "Impossible" if Iserlohn‘s demands can’t be satisfied.
 

Sample Input

5 10000 3
1 4 6
2 5 7
3 4 99
1 55 77
2 44 66

Sample Output

255

Source

 
解题:不知道是什么背包。。。感觉像分组1n背包。。。
 
技术分享
 1 #include <bits/stdc++.h>
 2 #define pii pair<int,int>
 3 using namespace std;
 4 const int maxn = 110;
 5 int n,m,o,dp[11][10001];
 6 vector< pii >goods[maxn];
 7 int main(){
 8     int a,b,c;
 9     while(~scanf("%d %d %d",&n,&m,&o)){
10         for(int i = 0; i < maxn; ++i) goods[i].clear();
11         for(int i = 0; i < n; ++i){
12             scanf("%d %d %d",&a,&b,&c);
13             goods[a].push_back(make_pair(b,c));
14         }
15         memset(dp,-1,sizeof dp);
16         memset(dp[0],0,sizeof dp[0]);
17         for(int i = 1; i <= o; ++i){
18             for(int j = 0; j < goods[i].size(); ++j){
19                 for(int k = m; k >= goods[i][j].first; --k){
20                     if(dp[i][k - goods[i][j].first] >= 0)
21                         dp[i][k] = max(dp[i][k],dp[i][k-goods[i][j].first] + goods[i][j].second);
22                     if(dp[i-1][k - goods[i][j].first] >= 0)
23                         dp[i][k] = max(dp[i][k],dp[i-1][k-goods[i][j].first] + goods[i][j].second);
24                 }
25             }
26         }
27         if(dp[o][m] >= 0) printf("%d\n",dp[o][m]);
28         else puts("Impossible");
29     }
30     return 0;
31 }
View Code

 

HDU 3033 I love sneakers!

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4448332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!