【01背包+完全背包】HDU3449-Consumer
来源:互联网 发布:熊猫加速器mac版 编辑:程序博客网 时间:2024/06/02 00:24
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3449
Problem 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 800300 2 30 50 25 80600 1 50 130400 3 40 70 30 40 35 60
Sample Output
210
代码:
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int Maxn=100050; // 数组开小了,给我报TLE;int N,W,t,m,w,v;int dp[Maxn],dp1[Maxn];int main(){ while(~scanf("%d%d",&N,&W)){ memset(dp,0,sizeof(dp)); for(int i=1;i<=N;i++){ scanf("%d%d",&t,&m); // 这里需要注意,我们将dp的值赋值给dp1,做01背包, // 保证每次01完全背包的全局最优解; memcpy(dp1,dp,sizeof(dp)); for(int j=1;j<=m;j++){ scanf("%d%d",&w,&v); // 单个盒子的01背包; for(int k=W-t;k>=w;k--){ dp1[k]=max(dp1[k],(dp1[k-w]+v)); } } // 每个盒子的完全背包; for(int j=t;j<=W;j++){ dp[j]=max(dp[j],dp1[j-t]); } } printf("%d\n",dp[W]); } return 0;}
0 0
- 【01背包+完全背包】HDU3449-Consumer
- HDU3449 - Consumer(依赖背包)
- HDU3449 Consumer 条件背包DP
- HDU3449 Consumer 变种背包,还是背包
- HDU3449 Consumer(有依赖背包)
- hdu3449(有限制条件的01背包)
- hdu3449 依赖背包
- 01背包,完全背包
- 01背包 完全背包
- 01背包/完全背包
- 01背包,完全背包
- 01背包,完全背包
- 【HDU3449】 consumer
- 01背包,完全背包, 多重背包
- 01背包,完全背包,多重背包
- 01背包、完全背包、多重背包详解
- 01背包,完全背包,多重背包
- 01背包、完全背包、多重背包
- mac电脑中javaweb不用odbc来连接access 数据库
- 史上最全的英语连读规则一网打尽
- hdu 1849 Rabbit and Grass(Nim博弈入门)
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
- EL
- 【01背包+完全背包】HDU3449-Consumer
- 浅谈微信红包的算法
- jstl
- mysql基础回顾(一)
- 微信开放平台API学习笔记——第一章:API的注册与官方Demo的调试
- 网站被攻击的总结反思
- 1.3a初识cout、cin与名称空间
- 1.4函数与返回值初探
- 1.4a函数的形参与实参