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]*/ /*以下四行是对于每双鞋的描述*/ ...
随机推荐
- DB Query Analyzer 5.04 is released, 63 articles concerned have been published
DB Query Analyzer 5.04 is released, 63 articles concerned have been published DB QueryAnalyzer is pr ...
- Android 它们的定义View (一)
转载请注明出处:http://blog.csdn.net/lmj623565791/article/details/24252901 非常Android入门程序员AndroidView.可能都是比較恐 ...
- 【Andord真】SlideMenu+ViewPagerIndictor双滑动边栏+滑动导航条
采取SlideMenu达到的效果侧边栏: 间 setContentView是设置主背景的布局 setBehindContentView是设置左边菜单的布局 setSecondaryMenu是设置右边的 ...
- tabBar隐藏与显现 hidesBottomBarWhenPushed
这个问题说简单也简单 但是如果不知道 可会让很多人吃苦 隐藏UITabBarController的tabBar, 我用它的一个属性hidesBottomBarWhenPushed隐 藏了,可以pop ...
- JavaScript 字符串实用常用操作
字符串截取1. substring()xString.substring(start,end)substring()是最常用到的字符串截取方法,它可以接收两个参数(参数不能为负值),分别是要截取的开始 ...
- MySQL-python 1.2.3 for Windows and Python 2.7, 32bit and 64bit versions -(亲测可用)
MySQL-python 1.2.3 for Windows and Python 2.7, 32bit and 64bit versions - See more at: http://www.co ...
- 【转】CodeGear RAD 2007 SP4
转自:http://blog.csdn.net/Rzhghost/article/details/2512150 CodeGear RAD 2007 up4最新下载及破解 官方http下载:http: ...
- My SQL和LINQ 实现ROW_NUMBER() OVER以及Fatal error encountered during command execution
Oracle 和SQL server都有ROW_NUMBER() OVER这个功能函数,主要用于分组排序,而MySQL 却没有 SELECT * FROM (SELECT ROW_NUMBER() O ...
- leetcode Trapping Rain Water pthon
class Solution(object): def trap(self,nums): leftmosthigh = [0 for i in range(len(nums))] leftmax=0 ...
- CodeForces 379 D. New Year Letter
枚举开头结尾的字母,枚举ac的个数,总AC个数就是两个Fibonacci数列的和..... D. New Year Letter time limit per test 1 second memory ...