https://www.luogu.org/problem/P2967

https://ac.nowcoder.com/acm/contest/1077/B

题目描述

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 Pi (1 <= Pi <= 1000) and a number of console-specific games Gi (1 <= Gi <= 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 GPj (1 <= GPj price <= 100) and a production value (1 <= PVj <= 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=$800 budget. The first console costs $300 and has 2 games with cost $30 and $25 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 种游戏主机,第 i 种主机的价格是 Pi,该主机有 Gi 个独占游戏。很明显,奶牛必须先买进一种游戏主机,才能买进在这种主机上运行的游戏。在每种主机中,游戏 j 的价格为 GPj

每头奶牛在玩了该游戏后的牛奶产量为PVj

农夫约翰的预算为 V。请帮助他确定应该买什么游戏主机和游戏,使得他能够获得的产出值的和最大。

样例说明 1

假设 现在有 N=3 种主机,预算为V=800。

第一种主机的售价为 300,并且有两款游戏:

游戏编号 GPj​ PVj
1 $30 50
2 $25 80

第二种主机的售价为 600,并且只有一款游戏:

游戏编号 GPj PVj​
1 $50 130

第二种主机的售价为 400,并且有三款游戏:

游戏编号 GPj PVj
1 $40 70
2 $30 40
3 $35 60

理想方案:

                              产量
预算: $800
主机 1 -$300
游戏 2 -$25 80
主机 3 -$400
游戏 1 -$40 70
游戏 3 -$35 60
-------------------------------------------
总和: 0 (≥ 0) 210

输入描述:

* 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: Pi, Gi, and Gi pairs of space-separated integers GPj, PVj

输出描述:

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

示例1

输入


输出


 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <math.h>
const int INF=0x3f3f3f3f;
typedef long long LL;
const int mod=1e9+;
const double PI=acos(-);
const int maxn=;
using namespace std;
//ios::sync_with_stdio(false);
// cin.tie(NULL); int n,v;
int DP[][]; int main()
{
scanf("%d %d",&n,&v);
for(int i=;i<=n;i++)
{
int cost,num;
scanf("%d %d",&cost,&num);
for(int j=cost;j<=v;j++)
DP[i][j]=DP[i-][j-cost];//买了i个平台剩下j元 (j-cost)为买其他剩的钱
for(int k=;k<=num;k++)//遍历每种游戏
{
int a,b;
scanf("%d %d",&a,&b);
for(int j=v;j>=cost+a;j--)
DP[i][j]=max(DP[i][j],DP[i][j-a]+b);//一维01背包问题
}
for(int j=;j<=v;j++)
DP[i][j]=max(DP[i][j],DP[i-][j]);//重新判断一次,判断这个平台到底是买还是不买更值
}
printf("%d",DP[n][v]);
return ;
}

一些题解:

https://www.cnblogs.com/hkpls/p/9908869.html

https://ac.nowcoder.com/acm/contest/view-submission?submissionId=41148893

https://www.cnblogs.com/Xxzxx/p/11336946.html

https://www.cnblogs.com/pile8852/p/9280310.html

https://blog.csdn.net/weixin_33835690/article/details/93431150

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

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

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

  2. LG_2967_[USACO09DEC]视频游戏的麻烦Video Game Troubles

    题目描述 Farmer John's cows love their video games! FJ noticed that after playing these games that his c ...

  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. iOS基础——通过案例学知识之xib、plist、mvc

    透过案例学习xib的使用.plist的使用.mvc在iOS的使用,今天要做的案例效果图 1.xib和nib xib文件可以被XCode编译成nib文件,xib文件本质上是一个xml文件,而nib文件就 ...

  2. NumPy - 数组(定义,拼接)

    NumPy 教程(数组) set_printoptions(threshold='nan') NumPy的数组中比较重要ndarray对象属性有: ndarray.ndim:数组的维数(即数组轴的个数 ...

  3. c 转二进制

    int nData = 1568;//转二进制 for (int i = sizeof(int) * 8 - 1; i >= 0; i--){ if ((nData >>i) &am ...

  4. XML--XSL

    参考 http://blog.51cto.com/cnn237111/1345998 https://www.w3.org/TR/2017/REC-xslt-30-20170608/ 声明 把文档声明 ...

  5. 读书笔记 - javascript 高级程序设计 - 第一章 简介

      第一章 简介   诞生时间 1995 最初用途 客服端验证 第一版标准 注意是标准 1997年 Ecma-262  一个完整的js实现由三部分组成 ECMAScript DOM 文档对象模型 BO ...

  6. 18 11 26 用多进程 多线程 携程 实现 http 服务器的创建

    下面是一个  多进程 服务器的创建 import socket import re import multiprocessing def service_client(new_socket): &qu ...

  7. 求1+2+3+…..+n

    [问题]求1+2+3+…+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). [思路]由于题目好多运算符不能用,我们只有想到使用递 ...

  8. 第一个eclipse maven项目!我超全!

    前言:以前一直用idea做东西,今天突然想试一下,没想到配置起来是真的麻烦!!!!会出现各种各样的问题,太晚了,本文只做出几处非常严重的问题,如有疑问,请私信,留言 准备:本文     JDK 1.8 ...

  9. Redis 在NETCore中的应用

    Redis 在NETCore中的应用 Redis 在netFramework中的应用  也一样 新建.NETCORE(webapi)项目 安装NuGet //查询NuGet语句 Find-Packag ...

  10. 数组分组(DP)

    一个长度为n的数组a,我们可以把它分成任意组,每一组是一段连续的区间. 比如数组1,2,3,4,5可以分成(1,2),(3,4,5)两个组.每个分组都有一个权值,这个权值就是分组里面每个数的乘积对10 ...