I love sneakers!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3265    Accepted Submission(s): 1337

Problem Description
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
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  2639 1712 3535 2415 3449 
 
 //93MS    844K    1142 B    C++
/* 题意:
有n双鞋子,m块钱,k种牌子,每双鞋子属于某个牌子,价格为b,价值为c,
现在问在满足在现有的金钱内买鞋,每个牌子的鞋最少有一双的情况下获得的最大价值,
不能满足则输出 Impossible 背包:
分组背包,并且每组至少一个。与传统的分组背包有点不同,难点是判断每组至少一个的
情况,此处采用标记法,先初始化 dp数组为-1,dp[0][0..V]为0,状态转移时判断前一状态
是否可行,可行在进行转移。 */
#include<iostream>
#include<vector>
using namespace std;
struct node{
int v;
int w;
node(int a,int b){
v=a;w=b;
}
};
vector<node>V[];
int dp[][];
int n,m,k;
int main(void)
{
int a,b,c;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(dp,-,sizeof(dp));
for(int i=;i<=m;i++) dp[][i]=; //初始化
for(int i=;i<=k;i++) V[i].clear();
for(int i=;i<n;i++){
scanf("%d%d%d",&a,&b,&c);
V[a].push_back(node(b,c));
}
for(int i=;i<=k;i++){
int n0=V[i].size();
for(int j=;j<n0;j++){
for(int v=m;v>=V[i][j].v;v--){
if(dp[i][v-V[i][j].v]!=-) //当前牌子转移状态
dp[i][v]=max(dp[i][v],dp[i][v-V[i][j].v]+V[i][j].w);
if(dp[i-][v-V[i][j].v]!=-) //前一牌字转移状态
dp[i][v]=max(dp[i][v],dp[i-][v-V[i][j].v]+V[i][j].w);
}
}
}
if(dp[k][m]==-) puts("Impossible");
else printf("%d\n",dp[k][m]);
}
return ;
}

hdu 3033 I love sneakers!(分组背包+每组至少选一个)的更多相关文章

  1. hdu 3033 I love sneakers! 分组背包

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 3033 分组背包(至少选一个)

    分组背包(至少选一个) 我真的搞不懂为什么,所以现在就只能当作是模板来用吧 如果有大牛看见 希望评论告诉我 &代码: #include <cstdio> #include < ...

  3. HDU3033I love sneakers!(分组背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=3033 本题的意思就是说现在有n种牌子的鞋子,每种品牌有一些不同的鞋,每双鞋子都有一个特定的权值,现在要求每种品牌 ...

  4. hdu3033 I love sneakers! 分组背包变形

    分组背包要求每一组里面只能选一个,这个题目要求每一组里面至少选一个物品. dp[i, j] 表示前 i 组里面在每组至少放进一个物品的情况下,当花费 j 的时候,所得到的的最大价值.这个状态可以由三个 ...

  5. 【hdu3033】分组背包(每组最少选一个)

    [题意] 有S款运动鞋,一个n件,总钱数为m,求不超过总钱数且每款鞋子至少买一双的情况下,使价值最大.如果有一款买不到,就输出“Impossible". 1<=N<=100  1 ...

  6. [HDU 3033] I love sneakers! (动态规划分组背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3033 题意:给你K种品牌,每种品牌有不同种鞋,现在每种品牌至少挑一款鞋,问获得的最大价值,如果不能每种 ...

  7. HDU 3033 I love sneakers! 我爱运动鞋 (分组背包+01背包,变形)

    题意: 有n<=100双鞋子,分别属于一个牌子,共k<=10个牌子.现有m<=10000钱,问每个牌子至少挑1双,能获得的最大价值是多少? 思路: 分组背包的变形,变成了相反的,每组 ...

  8. I love sneakers!(分组背包HDU3033)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. HDU 4341 Gold miner (分组背包)

    先把线按照距离原点的距离排序,然后用叉积把在同一条直线上的点放在一起, 把在同一条线上的点中的前i个点当成一个点就转化成了分组背包. 写if(kas++) putchar('\n') 居然PE了,PE ...

随机推荐

  1. Dockerfile中npm中Error: could not get uid/gid问题的解决方法

    dockerfile 中  使用 npm 的时候报错:   解决办法:https://github.com/tootsuite/mastodon/issues/802              

  2. Java语言利用Collections.sort对Map,List排序

    1.main方法包含TreeMap排序1,TreeMap排序2,HashMap排序,List<Integer>排序,List<Bean>排序,List<Map>排序 ...

  3. GUI小程序---理解GUI

    package com.gui; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent ...

  4. 【ospf-路由过滤】

  5. Chrome Google 快捷键

    窗口和标签页快捷方式 Ctrl+N 打开新窗口 按住 Ctrl‎ 键,然后点击链接 在新标签页中打开链接 按住 Shift 键,然后点击链接 在新窗口中打开链接 Alt+F4 关闭当前窗口 Ctrl+ ...

  6. 第一个网页(仿照当当网,仅仅使用CSS)

    这个网页是在学过CSS之后,对当当网首页进行模仿的网页,没有看当当网的网页源码,纯按照自己之前学的写的,由于是刚学过HTML和CSS才一个星期,所以里面有许多地方写的非常没有水平,仅仅用来学习使用,欢 ...

  7. GET TIME

    基本形式 GET TIME [FIELD tim]. オプション: ... FIELD tim 機能 FIELD オプションを使用しない場合. 日付および時刻のシステム項目 sy-datlo.sy-d ...

  8. netty学习记录2

    昨天晚上在看到7.2章MessagePack编码器和解码器开发这一章时,书里面没有贴出全部的代码,然后我按照我自己的想法把代码补全后,发现死活没有把代码跑通. 然后花了挺多时间在网上找,很多博客都贴出 ...

  9. Java RMI 入门指南

    开通博客也有好些天了,一直没有时间静下心来写博文,今天我就把两年前整理的一篇关于JAVA RMI入门级文章贴出来,供有这方面需要的同学们参考学习. RMI 相关知识 RMI全称是Remote Meth ...

  10. 【算法】 string 转 int

    [算法] string 转 int 遇到的一道面试题, 当时只写了个思路, 现给出具体实现 ,算是一种比较笨的实现方式 public class StringToInt { /// <summa ...