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. 《think in python》学习-5

    think in python -5 think in python -5 条件和递归 求模操作符% 用于整数,可以计算出第一个操作数除以第二个操作数的余数 7%3 #结果是2 求模操作符%有很多用途 ...

  2. C#程序之Main()方法

    一.Main()方法的简介 1.一般情况下,一个C#可执行程序只有一个应用程序对象(也就是就程序入口),但是在某些情况,可能会有多个应用程序对象(程序入口),如单元测试中,这个时候我们就需要通过命令行 ...

  3. android的Log日志打印管理工具类(一)

    android的Log日志的打印管理工具类: package com.gzcivil.utils; import android.util.Log; /** * 日志打印管理 * * @author ...

  4. OC 实现多选参数

    在iOS的开发过程中有许多方法都是有可选参数的,例如: + (instancetype)arrayWithObjects:(ObjectType)firstObj, ... NS_REQUIRES_N ...

  5. php汉字截取

    /** * 截取HTML,并自动补全闭合 * @param $html * @param $length * @param $end */ function subHtml($html,$length ...

  6. 安全的PHP代码编写准则

    原文链接 绝不要信任外部数据或输入 关于 Web 应用程序安全性,必须认识到的第一件事是不应该信任外部数据.外部数据(outside data) 包括不是由程序员在 PHP 代码中直接输入的任何数据. ...

  7. Python进阶之模块与包

    模块 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB","S ...

  8. js 报错 :object is not a function

    object is not a function 我遇到的具体问题是:js命名方法重复了,找到了别的地方,改个方法名就可以了 var h2_price = document.getElementByI ...

  9. HTTP请求大全

    1xx - 信息提示这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多个 1xx 响应.100 - 继续101 - 切换协议 2xx - 成功这类状态代码表明服务器成功地接受了客 ...

  10. MFC DLL资源动态切换

    在MFC使用过程中,遇到DLL资源与主EXE资源冲突问题. 出现这样的Bug,一时无从下手. 报错位置在核心代码中dlgcore.cpp. [cpp] view plaincopy BOOL AFXA ...