背包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;
}

最新文章

  1. ASP.NET MVC 异步获取和刷新ExtJS6 TreeStore
  2. 分享一个简单程序(webApi+castle+Automapper+Ef+angular)
  3. OllyDBG 1.10
  4. 2. xargs 命令
  5. 转载爱哥自定义View系列--Paint详解
  6. 【转】Android驱动开发之earlysuspend睡眠模式编程总结
  7. libeXosip2(2-2) -- eXosip2 network API
  8. phper談談最近重構代碼的感受(3)
  9. 广度优先搜索(BFS)——迷宫的最短路径
  10. 自签名的https证书是不安全的
  11. ajax和jquery使用技巧
  12. Java Excel导入导出(实战)
  13. adb通过wifi连接android设备
  14. jquery及jquery常用选择器使用
  15. 光照渲染[Unity]
  16. apache Apache winnt_accept: Asynchronous AcceptEx failed 错误的解决
  17. C# 同步调用、异步调用、异步回调
  18. C++的可移植性和跨平台开发
  19. 《X86汇编语言:从实模式到保护模式》读书笔记之引言
  20. 【CF103D】Time to Raid Cowavans(分块)

热门文章

  1. 在Python中操作文件之truncate()方法的使用教程
  2. 安装mysql数据库-centos7
  3. 001/Nginx高可用模式下的负载均衡与动静分离(笔记)
  4. C#调取接口时报错:服务器提交了协议冲突. Section=ResponseStatusLine
  5. 爬虫(十一)—— 请求库(三)pypeteer请求库
  6. php优化方法
  7. Lambda -语法使用,代码简化
  8. MySQL-第六篇DML语句
  9. 解决Ubuntu12.04下rpcbind: cannot open &#39;/var/run/rpcbind/rpcbind.xdr&#39; file for reading
  10. js提交map类型参数