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. Java中的文件和stream流的操作代码

    1.Java中FileRead方法的运用代码及详解 package example2;import java.io.FileReader;import java.io.IOException;clas ...

  2. 解决每次运行Xcode,都需要输入密码的问题

    新买的Mac,在安装了 Xcode 7.1的时候,不知道是配置信息哪里手残了一下,导致每次运行Xcode模拟器 后 都需要输入一次密码. 为此在网上也是查阅了不少的资料,当时 所谓的 XCode--- ...

  3. Linux之redis主从复制

    redis集群中的数据库复制就是通过主从同步实现的 主节点Master把数据分发给节点Salve 主从同步的好处在高可用, redis节点有冗余设计 redis主从同步的原理 1. 从服务器向主服务器 ...

  4. Angular : 基础语句说明, 响应式表单指令, 组件生命周期钩子

  5. 【Nginx一】Nginx服务器搭建

    Nginx服务器搭建 Nginx服务器搭建 下载Nginx源码包 安装Nginx 解压Nginx安装包 安装Nginx依赖 启动Nginx 下载Nginx源码包 官网下载地址 命令:wget http ...

  6. 解决软件启动报error while loading shared libraries: libgd.so.2: cannot open shared object错误

    解决软件启动报error while loading shared libraries: libgd.so.2: cannot open shared object错误 今天安装启动nginx的时候报 ...

  7. Android——搜索传统蓝牙设备

    一,主布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...

  8. 10-mongodb启动错误

    1.error信息 python@ubuntu:~$ mongod --22T17:: I CONTROL [initandlisten] MongoDB starting : pid= port= ...

  9. RHCE7认证学习笔记17——KickStart安装系统

    一.自动化安装系统工具 1.Cobbler    另一个自动化安装工具: 2.Kickstart 二.使用kickstart自动化安装系统 服务器安装的软件: 1.dhcp服务   [root@lin ...

  10. Python操作nosql数据库之redis

    一.NoSQL的操作 NoSQL,泛指非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得力不 ...