题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3449

Consumer

Description

FJ is going to do some shopping, and before that, he needs some boxes to carry the different kinds of stuff he is going to buy. Each box is assigned to carry some specific kinds of stuff (that is to say, if he is going to buy one of these stuff, he has to buy the box beforehand). Each kind of stuff has its own value. Now FJ only has an amount of W dollars for shopping, he intends to get the highest value with the money. 

Input

The first line will contain two integers, n (the number of boxes 1 <= n <= 50), w (the amount of money FJ has, 1 <= w <= 100000) Then n lines follow. Each line contains the following number pi (the price of the ith box 1<=pi<=1000), mi (1<=mi<=10 the number goods ith box can carry), and mi pairs of numbers, the price cj (1<=cj<=100), the value vj(1<=vj<=1000000) 

Output

For each test case, output the maximum value FJ can get 

Sample Input

3 800
300 2 30 50 25 80
600 1 50 130
400 3 40 70 30 40 35 60

Sample Output

210

大意:在购买一类物品之前,必须买另一种物品。

本题是购买袋子,有体积,但是没有价值。

AC代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
const int maxn=1e5+5;
const int INF=0x3f3f3f3f;int dp[maxn];
int temp[maxn];int main()
{int N,P;while(scanf("%d%d",&N,&P)==2){memset(dp,0,sizeof(dp));for(int i=1; i<=N; i++){int p,m;scanf("%d%d",&p,&m);memset(temp,-1,sizeof(temp));for(int k=p; k<=P; k++)temp[k]=dp[k-p];while(m--){int a,b;scanf("%d%d",&a,&b);for(int k=P; k>=a; k--)if(temp[k-a]!=-1)temp[k]=max(temp[k],temp[k-a]+b);}for(int k=1; k<=P; k++)dp[k]=max(dp[k],temp[k]);}printf("%d\n",dp[P]);}return 0;
}

一个写的好几种方法的博客:http://www.cnblogs.com/wuyiqi/archive/2011/11/26/2264283.html

转载于:https://www.cnblogs.com/a-clown/p/6040268.html

hdu 3449 有依赖性的01背包相关推荐

  1. HDu 3449 (有依赖的01背包) Consumer

    题意: 有n件物品,对应有不同的价格和价值,这是典型的01背包.但现在有了一个限制,要买物品先买能装这件物品的特定的盒子,盒子的价值为0 代码理解得还不是太好,感觉这是一个"二重" ...

  2. hdu 6149 Valley Numer II(01背包套状压dp)

    题目链接:hdu 6149 Valley Numer II 题意: 给你N个点,有k个为高点,其他为低点,现在这N个点有m条边,问你最多能组成多少个两个高点一个低点,低点和两个高点都有边相连这样的状态 ...

  3. hdu 2602 Bone Collector(01背包)

    题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...

  4. hdu 6092 Rikka with Subset 01背包 思维

    dp[i][j]表示前i个元素,子集和为j的个数.d[i][j] = d[i][j] + d[i-1][j-k] (第i个元素的值为k).这里可以优化成一维数组 比如序列为 1 2 3,每一步的dp值 ...

  5. hdu 1864 最大报销额01背包dp

     最大报销额 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Subm ...

  6. hdu 2546 饭卡(01背包)

    题意:只要最后留下的钱够5元,就可以买下最贵的食物,使得余额最低,其他的钱的使用就是一个最大背包问题了. 代码: #include<iostream> #include<cstrin ...

  7. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  8. hdu 2546 饭卡【01背包】

    题目链接:https://vjudge.net/contest/103424#problem/C 饭卡                                Time Limit: 5000/ ...

  9. HDU 5616 Jam's balance(01背包)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...

最新文章

  1. 周志华:“数据、算法、算力”,人工智能三要素在未来还要加上“知识”
  2. Android学习-- 基于位置的服务 LBS(基于百度地图Android SDK)--定位SDK
  3. TED演讲:区块链将如何改变世界?看完太震撼了!
  4. struts2+hibernate+spring配置管理(一)-配置文件2
  5. django-查询-F对象-Q对象
  6. python getopt_Python getopt
  7. php多次登录失败,PHPCMS登录后台失败次数过多解决办法
  8. 怎样看oracle删掉没有,肿么查看以前Oracle卸载干净没
  9. 华为私有云的搭建方案_华为关闭私有云真相
  10. 微信小程序实现倒计时功能(超简单)
  11. java excel 增加链接_Java 添加超链接到Excel文档
  12. 微信将迎来重大更新:绑定银行卡的用户请注意
  13. 怎样写好Git的commit信息
  14. 山西最新道路运输安全员模拟真题集及答案解析
  15. excel排名技巧:万能透视表加筛选找出销售冠军
  16. 阿里刘振飞:聚安全人之力 为全社会赋能
  17. 搜书吧自动购买(下载)功能实现
  18. 日本教育家多湖辉的《学生用功术》---2
  19. 如何学习Linux驱动开发?
  20. 【附源码】计算机毕业设计java校园招聘信息网站设计与实现

热门文章

  1. 【⛔拒绝内卷,学会shell,走遍天下都不怕⛔】shell编程基础
  2. 如何在 Linux 中使用 find
  3. Feign,Apache Http Client,OkHttp的区别
  4. zcmu2117(普通母函数)
  5. LSTM神经网络 和 GRU神经网络
  6. android retrofit入门,Android开发 retrofit入门讲解
  7. php根据单词截取英文语句,php按单词截取字符串的方法_PHP教程
  8. C#接口(Interface)理解
  9. 我拿什么融化你,冰冷的电子图书馆?
  10. 号码锁 Combination Lock