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 Value1       $30          502       $25          80The second console costs $600 and has only 1 game:Game #    Cost    Production Value1       $50          130The third console costs $400 and has 3 games:Game #    Cost    Production Value1       $40         702       $30         403       $35         60Farmer 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 ValueBudget:     $800      Console 1  -$300Game 2   -$25              80Console 3  -$400Game 1   -$40              70Game 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

输入

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

输出

210

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <queue>
 9 #include <set>
10 #include <map>
11 #include <math.h>
12 const int INF=0x3f3f3f3f;
13 typedef long long LL;
14 const int mod=1e9+7;
15 const double PI=acos(-1);
16 const int maxn=100010;
17 using namespace std;
18 //ios::sync_with_stdio(false);
19 //    cin.tie(NULL);
20
21 int n,v;
22 int DP[55][100010];
23
24 int main()
25 {
26     scanf("%d %d",&n,&v);
27     for(int i=1;i<=n;i++)
28     {
29         int cost,num;
30         scanf("%d %d",&cost,&num);
31         for(int j=cost;j<=v;j++)
32             DP[i][j]=DP[i-1][j-cost];//买了i个平台剩下j元 (j-cost)为买其他剩的钱
33         for(int k=1;k<=num;k++)//遍历每种游戏
34         {
35             int a,b;
36             scanf("%d %d",&a,&b);
37             for(int j=v;j>=cost+a;j--)
38                 DP[i][j]=max(DP[i][j],DP[i][j-a]+b);//一维01背包问题
39         }
40         for(int j=0;j<=v;j++)
41             DP[i][j]=max(DP[i][j],DP[i-1][j]);//重新判断一次,判断这个平台到底是买还是不买更值
42     }
43     printf("%d",DP[n][v]);
44     return 0;
45 }

一些题解:

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

转载于:https://www.cnblogs.com/jiamian/p/11386506.html

[USACO09DEC]视频游戏的麻烦Video Game Troubles(DP)相关推荐

  1. 洛谷 P3041 视频游戏的连击Video Game Combos(AC自动机+拓扑排序+数位DP)

    洛谷 P3041 视频游戏的连击Video Game Combos 难度一般,不过这个数位DP其实应该叫做记忆化搜索 题意:玩游戏时可以通过按键组合打出combo技能:然后是已知N个combo的按键方 ...

  2. luogu P3041 [USACO12JAN]视频游戏的连击Video Game Combos

    P3041 [USACO12JAN]视频游戏的连击Video Game Combos 题目大意: 给出n个字符串st[1-n],求一个长度为K的字符串,每匹配到st中的字符串就+1分,问最多能加几分 ...

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

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

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

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

  5. P3041 [USACO12JAN]视频游戏的连击Video Game Combos

    题意:贝西在玩一款游戏,该游戏只有三个技能键 "A""B""C"可用,但这些键可用形成N种(1 <= N<= 20)特定的组合技 ...

  6. 【USACO12JAN】—视频游戏的连击Video Game Combos(AC自动机+dp)

    描述 贝西在玩一款游戏,该游戏只有三个技能键 "A""B""C"可用,但这些键可用形成N种(1 <= N<= 20)特定的组合技 ...

  7. 【题解】[USACO12JAN]视频游戏的连击Video Game Combos

    好久没有写博客了,好惭愧啊--虽然这是一道弱题但还是写一下吧. 这道题目的思路应该说是很容易形成:字符串+最大值?自然联想到学过的AC自动机与DP.对于给定的字符串建立出AC自动机,dp状态dp[i] ...

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

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

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

    很早之前就做过啦 补一下题解 F(i,j)前i个的字符为j的匹配 注意end要累加 #include<iostream> #include<cstdio> #include&l ...

最新文章

  1. RDKit | 基于RDKit和scikit-learn的KNN模型预测Ames的致突变性
  2. 详解蚂蚁金服 SOFAJRaft:生产级高性能 Java 实现
  3. edge无法上网dns_如何在Microsoft Edge中通过HTTPS启用DNS
  4. 交个朋友回应罗永浩3年还清6亿元:争取年底还完
  5. 无缝的缓存读取:双存储缓存策略
  6. Hadoop系列之ToolRunner与GenericOptionsParser用法
  7. 海量中文语料上预训练ALBERT模型:参数更少,效果更好
  8. seqlist插入java_线性表插入c语言代码我想问的是seqlist *l中的*l不是太理解。它指向了哪里...
  9. excel文件如何撤销工作表保护
  10. pla3d打印材料密度_3D打印材料:透明PLA材料
  11. 《App架构师实践指南》---笔记
  12. COM in Wine(1)——COM基本概念
  13. SVN修改提交后的文件名
  14. 写一手好SQL很有必要
  15. java毕业设计物资租赁管理系统mybatis+源码+调试部署+系统+数据库+lw
  16. 回归综合案例——利用回归模型预测鲍鱼年龄
  17. android线上内存监控_如何在Android上监控(和减少)您的数据使用情况
  18. 抖音短视频源码中视频排序模块热门列表解决方案
  19. 解决联想ideapad 110如何进入bios界面修改禁用状态的VT选项问题
  20. python识别发票二维码_Python 实现二维码生成和识别

热门文章

  1. C/C++动态开辟数组【C++:new/delete(推荐):int *arr = new int[m];】【C++:vector】【C:malloc() free()】
  2. gabor 变换matlab,Gabor变换到底是什么鬼?
  3. MapReduce各个执行阶段
  4. tensorflow常用函数
  5. 本周内外盘行情回顾2022.3.6
  6. 经典Java开发教程 腾讯+字节+阿里面经真题汇总,斩获offer
  7. 高低温测试试验方法有哪些?
  8. 关于vue移动端下载图片
  9. Spring MVC集成Swagger2.0
  10. 2. 表的操作:创建表、修改表、列约束和表约束、数据操作、删除表