HDU 3033 分组背包变形(每种至少一个)
I love sneakers!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4464 Accepted Submission(s): 1824
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.
有n种物品,每种可能有多个,每个有不同体积和价值。初始手中有V的背包,现将所有种类至少一个装进背包中,若无法达到目标输出Impossible,否则输出最大的价值。
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <cmath>
- #include <set>
- using namespace std;
- #define N 105
- int max(int x,int y){return x>y?x:y;}
- int min(int x,int y){return x<y?x:y;}
- int abs(int x,int y){return x<?-x:x;}
- struct node{
- int v, w;
- };
- int dp[][];
- vector<node>ve[];
- int n;
- main()
- {
- int i, j, k;
- node p;
- int V;
- while(scanf("%d %d %d",&n,&V,&k)==){
- for(i=;i<=k;i++) ve[i].clear();
- for(i=;i<n;i++){
- scanf("%d %d %d",&j,&p.v,&p.w);
- ve[j].push_back(p);
- }
- memset(dp,-,sizeof(dp));
- memset(dp[],,sizeof(dp[]));
- for(i=;i<=k;i++){
- for(j=;j<ve[i].size();j++){
- p=ve[i][j];
- for(int v=V;v>=p.v;v--){
- if(dp[i][v-p.v]!=-) dp[i][v]=max(dp[i][v],dp[i][v-p.v]+p.w);
- if(dp[i-][v-p.v]!=-) dp[i][v]=max(dp[i][v],dp[i-][v-p.v]+p.w);
- }
- }
- }
- if(dp[k][V]==-) printf("Impossible\n");
- else printf("%d\n",dp[k][V]);
- }
- }
HDU 3033 分组背包变形(每种至少一个)的更多相关文章
- HDU 3033 分组背包(至少选一个)
分组背包(至少选一个) 我真的搞不懂为什么,所以现在就只能当作是模板来用吧 如果有大牛看见 希望评论告诉我 &代码: #include <cstdio> #include < ...
- HDU 3033 分组背包
给出N个物品.M金钱.W种类 给出N个物品的性质:所属种类,花费.价值 求每一种类物品至少一个的前提下,所能购买到的最大价值 dp[i][k]表示在第i种物品.总花费为k的最大价值 dp[i][k]= ...
- HDU 3033 组合背包变形 I love sneakers!
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1712 (分组背包入门)
http://acm.hdu.edu.cn/showproblem.php?pid=1712 问题 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].这些物品被划分为若干组, ...
- hdu3033 I love sneakers! 分组背包变形
分组背包要求每一组里面只能选一个,这个题目要求每一组里面至少选一个物品. dp[i, j] 表示前 i 组里面在每组至少放进一个物品的情况下,当花费 j 的时候,所得到的的最大价值.这个状态可以由三个 ...
- ACboy needs your help(HDU 1712 分组背包入门)
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 1712 分组背包
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu3033 I love sneakers! 分组背包变形(详解)
这个题很怪,一开始没仔细读题,写了个简单的分组背包交上去,果不其然WA. 题目分析: 分组背包问题是这样描述的:有K组物品,每组 i 个,费用分别为Ci ,价值为Vi,每组物品是互斥的,只能取一个或者 ...
- HDU 4341 分组背包
B - Gold miner Time Limit:2000MS Memory Limit:32768KB Description Homelesser likes playing ...
随机推荐
- iOS改变字母的大小写
使用lowercaseString,uppercaseString -(void)test{ NSString * str = @"person"; NSString * str1 ...
- background-sizi (转)
http://www.cnblogs.com/greenteaone/archive/2012/08/28/2659878.html (原创作者链接地址 ) Background-Size:[ & ...
- 我的git学习
当遇到不想commit的,而status已经现实出来了,可以使用 git rm -r --cached "fine name or 文件夹" 出现 Git – fatal: U ...
- NHibernate Query
1) Sql Group by .... 之前是这么写的,因为DateTime是YYYY-MM-DD HH:mm:SS 模式,我只想group 日期.这种写法再mysql,sqlserver.orac ...
- DataTable转换为Json字符串的三种方法
//第一种:使用StringBuilder public string DataTableToJson(DataTable table) { var JsonString = new StringB ...
- HTML5 中的Nav元素详解
什么是Nav元素 Nav元素可以用作页面导航的链接组,在导航链接组里面有很多的链接,点击每个链接可以链接到其他页面或者当前页面的其他部分,并不是所有的链接组都要被放在nav元素里面,我们只需要把最主要 ...
- Eclipse Building Workspace 解决办法
Eclipse 一直不停 building workspace... android开发论坛 juapk 完美解决总结 一.产生这个问题的原因多种 1.自动升级 2.未正确关闭 3.maven下载l ...
- [ubuntu]用ubuntu开发的日子----win7 ubuntu双系统
小子终于忍不了win7某些蛋疼的设定,看群里好多大牛推荐mac,但资金紧张,只好推而求其次使用ubuntu,但是由于公司工作环境是windows,所以还必须保留windows系统,一次决定双系统. 下 ...
- MySQL问题记录--python插入中文至MySQL提示SQLErroor:1366错误
一.在爬虫脚本做以下操作仍提示错误:SQL Error: 1366: Incorrect string value: "\xd0\xc2\xce\xc5-" for column ...
- Selenium ide录制回放错误Timed out after 30000ms
[error] Timed out after 30000ms 该问题可能是速度控制条播放速度过快导致,调整播放速度至slow