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. 简单实现仿UITabBarController界面

    第一步:添加两个占位View 第二步:添加子控制器 第三步:添加按钮 #import "ViewController.h" #define SCREEN_WIDTH ([UIScr ...

  2. sessionStorage和localStorage之间的差别

    <!DOCTYPE html><html> <head lang="en"> <meta charset="utf-8" ...

  3. Oracle视图,序列及同义词、集合操作

    一.视图(重点) 视同的功能:一个视图其实就是封装了一个复杂的查询语句.1.创建视图的语法:CREATE VIEW 视图名称 AS 子查询 范例:创建一个包含了20部门的视图CREATE VIEW e ...

  4. iOS协议

    ios中的协议:大家猛一看 感觉挺高深的  其实ios中的协议就是c#,java中的接口 只是变了一个形式: 自我感觉ios中的协议没有c#中的接口好  人家的接口就是固定你的程序内容的  而ios中 ...

  5. juce中的CallbackMessage

    这个类作为所有消息的基类,主要是包装了回调函数 virtual void messageCallback() = 0; /* ===================================== ...

  6. StormAPI简单使用

    StormAPI .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB",& ...

  7. sheelエラー、オブジェクトを解析中にエラーが発生しました。

  8. C++设计模式之装饰者模式

    #include "HandCake.h" //手抓饼 HandCake::HandCake() { ; this->name="手抓饼"; } Hand ...

  9. OSG中的几何体

    osg::Shape类 继承自osg::Object类: osg::Shape类是各种内嵌几何体的基类,不但可以用于剔除和碰撞检测,还可用于生成预定义的几何体对象: 常见的内嵌几何体包括: osg:: ...

  10. 深入学习PE文件(转)

    PE文件是Win32的原生文件格式.每一个Win32可执行文件都遵循PE文件格式.对PE文件格式的了解可以加深你对Win32系统的深入理解. 一. 基本结构. 上图便是PE文件的基本结构.(注意:DO ...