题目描述

Farmer John's cows love their video games! FJ noticed that after playing these games that his cows produced much more milk than usual, surely because contented cows make more milk.

The cows disagree, though, on which is the best game console. One cow wanted to buy the Xbox 360 to play Halo 3; another wanted to buy the Nintendo Wii to play Super Smash Brothers Brawl; a third wanted to play Metal Gear Solid 4 on the PlayStation 3. FJ wants to purchase the set of game consoles (no more than one each) and games (no more than one each -- and within the constraints of a given budget) that helps his cows produce the most milk and thus nourish the most children.

FJ researched N (1 <= N <= 50) consoles, each with a console price P_i (1 <= P_i <= 1000) and a number of console-specific games G_i (1 <= G_i <= 10). A cow must, of course, own a console before she can buy any game that is specific to that console. Each individual game has a game price GP_j (1 <= GP_j price <= 100) and a production value (1 <= PV_j <= 1,000,000), which indicates how much milk a cow will produce after playing the game. Lastly, Farmer John has a budget V (1 <= V <= 100,000) which is the maximum amount of money he can spend. Help him maximize the sum of the production values of the games he buys.

Consider one dataset with N=3 consoles and a V=800budget.Thefirstconsolecosts800 budget. The first console costs 800budget.Thefirstconsolecosts300 and has 2 games with cost 30and30 and 30and25 and production values as shown:

Game # Cost Production Value

1 $30 50

2 $25 80

The second console costs $600 and has only 1 game:

Game # Cost Production Value

1 $50 130

The third console costs $400 and has 3 games:

Game # Cost Production Value

1 $40 70

2 $30 40

3 $35 60

Farmer John should buy consoles 1 and 3, game 2 for console 1, and games 1 and 3 for console 3 to maximize his expected production at 210:

                            Production Value
Budget: $800
Console 1 -$300
Game 2 -$25 80
Console 3 -$400
Game 1 -$40 70
Game 3 -$35 60
-------------------------------------------
Total: 0 (>= 0) 210

农夫约翰的奶牛们游戏成瘾!本来约翰是想要按照调教兽的做法拿她们去电击戒瘾的,可是 后来他发现奶牛们玩游戏之后比原先产更多的奶.很明显,这是因为满足的牛会产更多的奶.

但是,奶牛们在哪个才是最好的游戏平台这个问题上产生了巨大的分歧.约翰想要在给定的 预算内购入一些游戏平台和一些游戏,使他的奶牛们生产最多的奶牛以养育最多的孩子.

约翰研究了N种游戏平台,每一种游戏平台的价格是Pi 并且每一种游戏平台有Gi个只能在这种平台上运行的游戏.很明显,奶牛必须 先买进一种游戏平台,才能买进在这种游戏平台上运行的游戏.每一个游戏有一个游戏的价 格GPi并且有一个产出值PVj< 1000000),表示一只牛在玩这个游戏之后会产出多少牛奶.最后,农夫约翰的预算为V<100000),即他最多可以花费的金钱.请 帮助他确定应该买什么游戏平台和游戏,使得他能够获得的产出值的和最大.

输入输出格式

输入格式

  • Line 1: Two space-separated integers: N and V

  • Lines 2..N+1: Line i+1 describes the price of and the games

available for console i; it contains: P_i, G_i, and G_i pairs of space-separated integers GP_j, PV_j

输出格式

  • Line 1: The maximum production value that Farmer John can get with his budget.

样例

INPUT

3 800

300 2 30 50 25 80

600 1 50 130

400 3 40 70 30 40 35 60

OUTPUT

210

SOLUTION

多重背包dp

考场上写崩掉了,没事瞎用树形dp的正在面壁思过中。。。

其实本体的思路应该是非常清晰的,所以这里重点还是看一下代码的实现吧。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long LL;
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-48;ch=getchar();}
return x*f;}
const int N=550,M=101000;
short n,m,V,cnt=0,id=0;
int f[2][M],ans=0;
int main(){
int i,j;
n=read();V=read();memset(f,0,sizeof(f));
for (i=1;i<=n;++i){
int p=read(),g=read();
for (j=p;j<=V;++j) f[i&1][j]=f[(i-1)&1][j-p];//先扣去买这个平台的游戏的平台费用
while (g--){
int cst=read(),pdc=read();
for (j=V;j>=cst+p;--j)
f[i&1][j]=Max(f[i&1][j],f[i&1][j-cst]+pdc);//正常的背包转移
}
for (j=0;j<=V;++j) f[i&1][j]=Max(f[i&1][j],f[(i-1)&1][j]);//或者我们索性不买这个平台
}
printf("%d\n",f[n&1][V]);
return 0;
}

LG_2967_[USACO09DEC]视频游戏的麻烦Video Game Troubles的更多相关文章

  1. P2967 [USACO09DEC]视频游戏的麻烦Video Game Troubles

    冲刺阶段的首篇题解! 题目链接:P2967 [USACO09DEC]视频游戏的麻烦Video Game Troubles: 题目概述: 总共N个游戏平台,金额上限V元,给出每个游戏平台的价钱和其上游戏 ...

  2. [USACO09DEC]视频游戏的麻烦Video Game Troubles(DP)

    https://www.luogu.org/problem/P2967 https://ac.nowcoder.com/acm/contest/1077/B 题目描述 Farmer John's co ...

  3. <USACO09DEC>视频游戏的麻烦Video Game Troublesの思路

    emm今天模拟赛的题.神奇地A了 #include<cstdio> #include<cstring> #include<iostream> #include< ...

  4. [Luogu2967] 视频游戏的麻烦Video Game Troubles

      农夫约翰的奶牛们游戏成瘾!本来约翰是想要按照调教兽的做法拿她们去电击戒瘾的,可是 后来他发现奶牛们玩游戏之后比原先产更多的奶.很明显,这是因为满足的牛会产更多的奶. 但是,奶牛们在哪个才是最好的游 ...

  5. 【USACO12JAN】视频游戏的连击Video Game Combos

    题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...

  6. [洛谷3041]视频游戏的连击Video Game Combos

    题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...

  7. [USACO12JAN]视频游戏的连击Video Game Combos(AC自动机+DP)

    Description 贝西正在打格斗游戏.游戏里只有三个按键,分别是“A”.“B”和“C”.游戏中有 N 种连击 模式,第 i 种连击模式以字符串 Si 表示,只要贝西的按键中出现了这个字符串,就算 ...

  8. [Luogu3041][USACO12JAN]视频游戏的连击Video Game Combos

    题面 sol 设\(f_{i,j}\)表示填了前\(i\)个字母,在\(AC\)自动机上跑到了节点\(j\)的最大得分.因为匹配需要暴跳\(fail\)所以预先把\(fail\)指针上面的匹配数传下来 ...

  9. 洛谷P3041 视频游戏的连击Video Game Combos [USACO12JAN] AC自动机+dp

    正解:AC自动机+dp 解题报告: 传送门! 算是个比较套路的AC自动机+dp趴,,, 显然就普普通通地设状态,普普通通地转移,大概就f[i][j]:长度为i匹配到j 唯一注意的是,要加上所有子串的贡 ...

随机推荐

  1. 证书打印CSS知识点总结

    需求: 1.证书内容动态填充: 2.证书背景图不要求打印,只为展示作用: 3.打印内容兼容屏幕分辨率: 实现: <!-- 外层div宽度为背景图片宽 --> <div style=& ...

  2. 周末畅谈 | 我是如何在硅谷获得年薪30万美金Offer的?

    本文讲述了一位硅谷软件工程师的面试经验,他分享了他如何在硅谷拿到最终30万美金年薪的Offer,原文摘自:https://blog.usejournal.com/how-i-negotiated-a- ...

  3. UML-基于GRASP对象设计步骤

    在OO设计建模的时候,在最后考虑系统启动时需要初始化的内容. 1.从用例开始,以下是一步步设计用例实现 处理销售 2.SSD 我们选择: makeNewSale 3.编写操作契约(复杂用例场景时) 4 ...

  4. python format输出

    http://www.cnblogs.com/nulige/p/6115793.html 2.Format 方式 [[fill]align][sign][#][0][width][,][.precis ...

  5. python 2.7编译安装

    一 官网下载python2.7源码: python安装pip python -m ensurepip --default-pip

  6. Python笔记_第一篇_面向过程_第一部分_0.开场白

    *什么是Python? Python是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido(吉多) van Rossum于1989年发明,第一个公开版本发行于1991年.在国外应用非常的广泛,国 ...

  7. Android java项目中引用kotlin,混合开发工程配置

    https://www.jianshu.com/p/9220227cdfb3 buildscript { ext.kotlin_version = '1.2.71' repositories { go ...

  8. 886A. ACM ICPC#均值分配问题(暴力)

    题目出处:http://codeforces.com/problemset/problem/886/A 题目大意:已知六个人得分,问是否能分成两个三人队使得每个队伍得分加和相等 #include< ...

  9. Oracle之纵向数据转换横向数据

    资源二  来源  http://www.cnblogs.com/gkl0818/archive/2009/02/25/1398078.html 1.固定列数的行列转换如student subject ...

  10. dlib安装踩过的坑

    使用到dlib时遇到了下载错误,不能正常安装 以下是成功安装的记录: 首先打开Anaconda prompt选定一个python环境,安装cmake和boost pip install cmake - ...