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. 如何安全地跨窗体调用Timer控件 从一个窗体调用控制另外一个窗体的控件

    具体的情况是Form1中有一个Timer2时钟,Timer2时钟事件弹出Warning窗体,点击Warning窗体上面的按钮,重新激活一下Form1中的Timer2.从而实现了从一个窗体调用另外一个窗 ...

  2. 关于okHttp框架的使用

    在之前的项目中,使用传统的HttpClient来返回一个图片信息流的时候总是报错,最后发现是因为传统的传输方式会对流的大小有限制,当超过某个值的时候就会报异常,最后决定使用OkHttp框架来解决这个问 ...

  3. MySQL版本详解

    一.版本说明 1.1.MySQL相关连接 MySQL官网:https://www.mysql.com/ MySQL下载:https://dev.mysql.com/downloads/mirrors/ ...

  4. css常用样式属性详细介绍

    对于初学css的来说,肯定会觉得这么多样式不好记,而且记住了也容易忘,其实刚开始我们不用去记这么多的样式,确实是记了也会忘,刚开始只需记住一些常用的就可以了,然后在慢慢的使用过程当中接触并学习一些高级 ...

  5. 【GUI】一、Swing外观框架BeautyEye使用

    一.Swing外观框架BeautyEye使用 1.1 导包 BeautyEye.jar 1.2 使用BeautyEye L&F public static void main(String[] ...

  6. 016---Django的ModelForm

    对于forms组件虽然可以帮我们渲染html页面,也可以做校验,但是,保存到数据库要取各字段的值,还要手动保存.所以引入了一个新的组件 这是一个神奇的组件,通过名字我们可以看出来,这个组件的功能就是把 ...

  7. 学习RUNOOB.COM进度一

    了解MongoDB 由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能. 特点 面向文档,操作简单容易 设置任何索引,实现更快排序 本地 ...

  8. mongodb常用命令学习笔记

    mongodb常用命令学习笔记 创建数据库 use DATABASE_NAME eg: use users; 如果数据库不存在,则创建数据库,否则切换到指定数据库.要显示刚刚创建的数据库,需要向数据库 ...

  9. python2.7练习小例子(十三)

        13):题目:将一个正整数分解质因数.例如:输入90,打印出90=2*3*3*5.     程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成.(1)如果这个质数恰等于 ...

  10. kafka监听类

    package com.datad.dream.service; import com.alibaba.fastjson.JSON; import com.datad.dream.dao.KafkaI ...