HDU3449Consumer题解动态规划DP

本文介绍了一种购物场景下的背包问题,通过动态规划方法解决了如何在有限预算内获得最大价值的问题。考虑了商品与特定盒子之间的依赖关系,以及不同商品的价值。

Consumer

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others)
Total Submission(s): 174    Accepted Submission(s): 92

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 800 300 2 30 50 25 80 600 1 50 130 400 3 40 70 30 40 35 60
 

 

Sample Output
  
210
 

 

Source
有依赖的背包,改编于USACO DEC09 Problem 'vidgame'
直接用这个标程AC
详情见《背包九讲》P07有依赖的背包问题
vidgame官方解题报告:

USACO DEC09 Problem 'vidgame' Analysis
by Alex Schwendner

这是一个动态规划的问题。


不考虑需要购买游戏机,这就是一个背包问题,游戏价格GP_j是大小,产生价值PV_j是该背包所求的价值,预算V则是背包的大小。如果我们不管购买游戏机,我们可以定义prod[j][c]是我们选择到第j个游戏和总花费为c美元时的最大价值。这样可以推导出:

prod[j][c] = max(prod[j-1][c], PV_j + prod[j-1][c - GP_j])

对于每个新的游戏j,我们可以不买它,或者我们可以花费GP_j元买它,并得到一个PV_j的价值。然后,请注意一旦我们购买了一个游戏机i,那么选择游戏机i上能够玩的游戏也就变成了一个简单的背包,我们仍可以通过以上的方法解决。也就是说,对于给定的游戏机i,我们计算出游戏机i上能玩的所有游戏的prod[j][c],这就告诉我们对于每一个预算我们应该购买哪些能在游戏机i上玩的游戏。

最后一步,我们选择需要购买的游戏机。将问题考虑为一个关于购买游戏机的背包问题,不过每一个游戏机并不是只有单一的成本和价值:
我们花在每一个游戏机上的费用,取决于我们所购买游戏和相应价值的多少。对于游戏机i的每一个prod[j][c]表示我们可以购买的不同的“游戏机i组合包”。在循环到i时,我们可以选择购买游戏机i和其中一个“游戏机i组合包”,或者我们可以直接跳过这个游戏机i。这样问题就分解了一个关于游戏机的背包程序,以及计算每一个游戏机i所有prod[j][c]的背包子程序。当我们就完成了这个动态规划后,就得到了对于所有游戏机的最优值。

 

HDU3449代码

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值