hdu3033I love sneakers! (分组背包,错了很多次)
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.
1 4 6
2 5 7
3 4 99
1 55 77
2 44 66
#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! (分组背包,错了很多次)的更多相关文章
- HDU3033I love sneakers!(分组背包)
http://acm.hdu.edu.cn/showproblem.php?pid=3033 本题的意思就是说现在有n种牌子的鞋子,每种品牌有一些不同的鞋,每双鞋子都有一个特定的权值,现在要求每种品牌 ...
- I love sneakers!(分组背包HDU3033)
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3033 I love sneakers! 分组背包
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 3033 I love sneakers!(分组背包+每组至少选一个)
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu3033 I love sneakers! 分组背包变形
分组背包要求每一组里面只能选一个,这个题目要求每一组里面至少选一个物品. dp[i, j] 表示前 i 组里面在每组至少放进一个物品的情况下,当花费 j 的时候,所得到的的最大价值.这个状态可以由三个 ...
- hdu3033 I love sneakers! 分组背包变形(详解)
这个题很怪,一开始没仔细读题,写了个简单的分组背包交上去,果不其然WA. 题目分析: 分组背包问题是这样描述的:有K组物品,每组 i 个,费用分别为Ci ,价值为Vi,每组物品是互斥的,只能取一个或者 ...
- HD3033I love sneakers!(分组背包+不懂)
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
- 【HDU】I love sneakers!(分组背包)
看了许多的题解,都有题目翻译,很不错,以后我也这样写.直接翻译样例: /*鞋子的数量N[1, 100]; 拥有的金钱M[1, 1w]; 品牌数目[1, 10]*/ /*以下四行是对于每双鞋的描述*/ ...
随机推荐
- Android上下左右滑动,显示底层布局
转载博客地址:http://www.cnblogs.com/flyme2012/p/4106308.html 闲着没事做了一个小东西.Android的上下左右滑动,显示底层布局.可以做类似于QQ消息列 ...
- javascript高级知识分析——函数访问
代码信息来自于http://ejohn.org/apps/learn/. 可以通过函数的名字在它的内部引用它. function yell(n){ return n > 0 ? yell(n-1 ...
- asp.net RadioButton控件基础
RadioButton按钮呢,必须要设置groupname属性的值才能将多个RadioButton按钮设置为单选按钮,当AutoPostBack="true"的时候,在change ...
- 今天是迅驰ORM的诞生之日。
欢迎各位朋友来造访,最主要还是那一点:版权所有,请尊重驰哥的著作版权,侵权必追究法律责任. 最后来一句刘德华的歌曲:独自去偷欢,我谢绝你监管!快乐心中常为我伴.
- Android BaseAdapter
ListView显示与缓存机制: 只会加载当前屏幕所要显示的数据.显示完成就会被回收到Recycler中. BaseAdapter 基本结构: public int g ...
- Could not find class 'XXX.activity‘', referenced from method 'YYYY'
Could not find class 'XXX.activity‘', referenced from method 'YYYY'的解决方案: 出现这个错误.是由于eclipse升级ADT所导致的 ...
- javascript 动态创建表格
<html> <head> <script> function createTable(rows,lines){ this.rows=rows; this.line ...
- 美国地质调研局USGS
https://lta.cr.usgs.gov/get_data/ http://www.usgs.gov/
- windows环境中mysql忘记root密码的解决办法
原文地址:http://www.cnblogs.com/linuxnotes/archive/2013/03/09/2951101.html windows下重置Mysql Root密码的方法mysq ...
- 最近招两个兼职的活(PHP和JSP)
我这里的活,都是兼职写作的,是两本入门教程, 一本是PHP+Nginx 一本是JSP+Servlet. 都是入门教程,有署名有稿酬,有兴趣的可以联系 QQ:837652732 验证:PHP或Java ...