I love sneakers!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4602    Accepted Submission(s): 1893

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
2009 Multi-University Training Contest 13 - Host by HIT



分组背包+01背包,要求每组物品最少取一个

#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; typedef struct node
{
int Fee;
int val;
} SN; SN a;
int n,m,K;
int Dp[12][11000];
vector<SN>s[12];
int main()
{
int flag,fe,va;
while(~scanf("%d %d %d",&n,&m,&K))
{
memset(Dp,-1,sizeof(Dp));
memset(Dp[0],0,sizeof(Dp[0]));
for(int i=0; i<=K; i++)
{
s[i].clear();
}
for(int i=1; i<=n; i++)
{
scanf("%d %d %d",&flag,&fe,&va);
a.Fee=fe;
a.val=va;
s[flag].push_back(a);
}
for(int i=1; i<=K; i++)
{
for(int j=0;j<s[i].size();j++)
{
for(int k=m;k>=s[i][j].Fee;k--)
{
if(Dp[i][k-s[i][j].Fee]!=-1)//顺序不可颠掉
{
Dp[i][k]=max(Dp[i][k],Dp[i][k-s[i][j].Fee]+s[i][j].val);
}
if(Dp[i-1][k-s[i][j].Fee]!=-1)
{
Dp[i][k]=max(Dp[i][k],Dp[i-1][k-s[i][j].Fee]+s[i][j].val);
} }
}
}
if(Dp[K][m]==-1)
{
printf("Impossible\n");
}
else
{
printf("%d\n",Dp[K][m]);
}
}
return 0;
/*
4 5 2
1 2 3
1 3 2
2 2 3
2 3 2 3 5 3
1 2 5
2 2 1
3 2 2 3 5 3
1 0 5
2 0 1
3 0 2
*/
}

 

I love sneakers!(分组背包HDU3033)的更多相关文章

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

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

  2. hdu3033 I love sneakers! 分组背包变形(详解)

    这个题很怪,一开始没仔细读题,写了个简单的分组背包交上去,果不其然WA. 题目分析: 分组背包问题是这样描述的:有K组物品,每组 i 个,费用分别为Ci ,价值为Vi,每组物品是互斥的,只能取一个或者 ...

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

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

  4. hdu 3033 I love sneakers!(分组背包+每组至少选一个)

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

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

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

  6. dp之分组背包hdu3033 最少取1次的解法(推荐)

    题意:有n双鞋子,m块钱,k个品牌,(一个品牌可以有多种价值不同的鞋子),接下来n种不同的鞋子,a为所属品牌,b为要花费的钱,c为所能得到的价值.每种价值的鞋子只会买一双,有个人有个伟大的梦想,每个品 ...

  7. HDU3033 I love sneakers!———分组背包

    这题的动态转移方程真是妙啊,完美的解决了每一种衣服必须买一件的情况. if(a[x][i-c[x][j].x]!=-1) a[x][i]=max(a[x][i],a[x][i-c[x][j].x]+c ...

  8. HD3033I love sneakers!(分组背包+不懂)

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

  9. hdu3033I love sneakers! (分组背包,错了很多次)

    Problem Description After months of hard working, Iserlohn finally wins awesome amount of scholarshi ...

随机推荐

  1. getch()函数

    这个函数是一个不回显函数,当用户按下某个字符时,函数自动读取,无需按回车,有的C语言命令行程序会用到此函数做游戏,但是这个函数并非标准函数,要注意移植性! 中文名 无 外文名 getch 头文件 co ...

  2. Lintcode: Sort Colors II

    Given an array of n objects with k different colors (numbered from 1 to k), sort them so that object ...

  3. map容器

    map容器一般用于对字符串进行编号,主要用于建图方面,例如把城市名按数字进行编号 #include"stdio.h" #include"string.h" #i ...

  4. C# Enum Type

    class Program { public enum TimeOfDay { Morining, Afternoon, Evening } static void Main(string[] arg ...

  5. [转]数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

    一.MySQL   MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换 服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失 ...

  6. 压缩 & 解压缩 命令汇总:tar、zip & unzip、

    1. tar命令详解     格式:tar [-cxtzjvfpPN] 文件与目录 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五 ...

  7. C++之路进阶——codevs1285(宠物收养所)

    1285 宠物收养所  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description 最近,阿Q开了一间宠物收养所.收养所提供两种服 ...

  8. javaIO整理

    写在前面:本文章基本覆盖了java IO的全部内容,java新IO没有涉及,因为我想和这个分开,以突出那个的重要性,新IO哪一篇文章还没有开始写,估计很快就能和大家见面.照旧,文章依旧以例子为主,因为 ...

  9. GC是什么? 为什么要有GC?

    GC是什么? 为什么要有GC?  GC是垃圾收集器.  程序员不用担心内存管理,因为垃圾收集器会自动进行管理.要请求垃圾收集,可以调用下面的方法之一:  System.gc() Runtime.get ...

  10. linux第6天 流协议-粘包

    今天学习的主要是对第5天的加强. 比如服务器的多进程,点对点应用聊天程序.父进程子进程互发消息.等等. 流协议-粘包 一般TCP协议会出现粘包,粘包产生的原因一般为.TCP协议是流式传输,不会根据用户 ...