[USACO09DEC] Video Game Troubles
2024-09-06 01:31:55
背包DP;有依赖的背包问题
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n, V;
int f[2][100003];
int main() {
scanf("%d%d", &n, &V);
for (int i=1, P, G; i<=n; ++i) {
scanf("%d%d", &P, &G);
for (int j=V; j>=P; --j) f[i&1][j]=f[(i-1)&1][j-P]; // suppose we have to buy it
for (int j=1, w, c; j<=G; ++j) {
scanf("%d%d", &c, &w);
for (int k=V; k>=c+P; --k) f[i&1][k]=max(f[i&1][k], f[i&1][k-c]+w);
}
for (int j=V; j>=0; --j) f[i&1][j]=max(f[(i-1)&1][j], f[i&1][j]); // revise
}
printf("%d\n", f[n&1][V]);
return 0;
}
最新文章
- ASP.NET MVC 异步获取和刷新ExtJS6 TreeStore
- 分享一个简单程序(webApi+castle+Automapper+Ef+angular)
- OllyDBG 1.10
- 2. xargs 命令
- 转载爱哥自定义View系列--Paint详解
- 【转】Android驱动开发之earlysuspend睡眠模式编程总结
- libeXosip2(2-2) -- eXosip2 network API
- phper談談最近重構代碼的感受(3)
- 广度优先搜索(BFS)——迷宫的最短路径
- 自签名的https证书是不安全的
- ajax和jquery使用技巧
- Java Excel导入导出(实战)
- adb通过wifi连接android设备
- jquery及jquery常用选择器使用
- 光照渲染[Unity]
- apache Apache winnt_accept: Asynchronous AcceptEx failed 错误的解决
- C# 同步调用、异步调用、异步回调
- C++的可移植性和跨平台开发
- 《X86汇编语言:从实模式到保护模式》读书笔记之引言
- 【CF103D】Time to Raid Cowavans(分块)
热门文章
- 在Python中操作文件之truncate()方法的使用教程
- 安装mysql数据库-centos7
- 001/Nginx高可用模式下的负载均衡与动静分离(笔记)
- C#调取接口时报错:服务器提交了协议冲突. Section=ResponseStatusLine
- 爬虫(十一)—— 请求库(三)pypeteer请求库
- php优化方法
- Lambda -语法使用,代码简化
- MySQL-第六篇DML语句
- 解决Ubuntu12.04下rpcbind: cannot open &#39;/var/run/rpcbind/rpcbind.xdr&#39; file for reading
- js提交map类型参数