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
题目意思:用M钱去卖东西,有k个品牌,要求:1.用M钱必须满足能买到k种品牌,每种品牌至少一样。2每样东西只买一个。
#include<stdio.h>
#define inf -0x7fffffff
struct nn
{
int k,v[105],u[105];
}T[15];
int M,dp[15][10005];
int max(int a,int b,int c)
{
if(a<b)a=b;
if(a<c)a=c;
return a;
}
void fenzupack(int t)
{
for(int e=1;e<=T[t].k;e++)
{
int w,use;
w=T[t].v[e]; use=T[t].u[e];
for(int m=M;m>=use;m--)
{
dp[t][m]=max(dp[t][m],dp[t-1][m-use]+w,dp[t][m-use]+w);//关建
}
}
}
int main()
{
int n,K,ty,use,w,m;
while(scanf("%d%d%d",&n,&M,&K)==3)
{
for(int j=0;j<=M;j++) dp[0][j]=0;
for(int i=1;i<=K;i++)
{
T[i].k=0;
for(int J=0;J<=M;J++)
dp[i][J]=inf;
}
while(n--)
{
scanf("%d%d%d",&ty,&use,&w);
T[ty].k++; m=T[ty].k;
T[ty].u[m]=use;
T[ty].v[m]=w;
}
for(int t=1;t<=K;t++)
{
fenzupack(t);
}
if(dp[K][M]>=0)
printf("%d\n",dp[K][M]);
else
printf("Impossible\n");
}
}
/*
5 50 3
1 20 30
2 30 500
3 20 60
2 10 10
3 40 10 3 5 3
1 6 0
2 0 0
3 0 0 3 5 3
1 0 5
2 0 1
3 0 2 3 5 3
1 0 0
2 0 0
3 0 0 5 10000 3
1 4 6
2 5 7
3 4 99
1 55 77
2 44 66 100
Impossible
8
0
255
*/

hdu3033I love sneakers! (分组背包,错了很多次)的更多相关文章

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

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

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

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

  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. hdu3033 I love sneakers! 分组背包变形

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

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

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

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

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

  8. 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 ...

  9. 【HDU】I love sneakers!(分组背包)

    看了许多的题解,都有题目翻译,很不错,以后我也这样写.直接翻译样例: /*鞋子的数量N[1, 100]; 拥有的金钱M[1, 1w]; 品牌数目[1, 10]*/ /*以下四行是对于每双鞋的描述*/ ...

随机推荐

  1. deferred initcalls与模块化

    deferred initcalls与模块化 有两个技术可以加快kernel的启动速度: 1.deferred initcalls 2.模块化 它们的思想类似,都是将非必要的模块初始化推迟到内核启动之 ...

  2. PHP自学3——在html的<table>标签中显示用户提交表单

    为了更好地显示用户提交表单,本节将在上一节的基础上将读取的用户表单显示在html的<table>标签中,这一节将用到和数组有关的知识. 本节代码将从外部文件(.txt文件)中读取信息于指定 ...

  3. JAVA-反射-getGenericSuperclass()

    1 public class Person<T> { 2 3 } 4 5 import java.lang.reflect.ParameterizedType; 6 import java ...

  4. linux循环递归设置权限

    这里给出一个循环递归得到对文件夹和文件分别有效的设置方法: find /path -type f -exec chmod 644 {} \; #对目录和子目录里的文件 find /path -type ...

  5. git本地仓库与github远程仓库链接协议问题

    前提条件:有github账号,本地安装了git,能上网. 环境:ubuntu14.0.4LTS 首先在你得在github上创建一个仓库new repository,然后再本地创建一个文件夹mkdir ...

  6. 利用oxygen编辑并生成xml文件,并使用JAVA的JAXB技术完成xml的解析

    首先下载oxygen软件(Oxygen XML Editor),目前使用的是试用版(可以安装好软件以后get trial licence,获得免费使用30天的权限,当然这里鼓励大家用正版软件!!!) ...

  7. 怎样在Eclipse中使用debug模式调试程序

    最基本的操作是: 1, 首先在一个java文件中设断点,然后运行,当程序走到断点处就会转到debug视图下, 2, F5键与F6键均为单步调试,F5是step into,也就是进入本行代码中执行,F6 ...

  8. c语言中的制表符\t与空格

    (本文不讨论制表符与空格缩进问题) 编程过程中,我们常常用多个空格或制表符分隔两个字符串,那么这两个在显示效果上有什么区别呢? 比较如下两行代码的输出效果 代码1: printf("1\t1 ...

  9. 【异常处理】java.lang.NoClassDefFoundError

    Exception in thread"main" java.lang.NoClassDefFoundError:org/apache/commons/lang/exception ...

  10. ASP.NET Identity 系列笔记目录

    编写目的 混迹博客园已经有一段时间了,一直都是在学习各路大神的文章,自己却没有做出什么贡献,所以觉得应该写一点点内容和大家一起分享.但是本人实在才疏学浅,有心无力啊!正好最近在学习 Microsoft ...