#include <iostream>
#include <algorithm>
using namespace std;
const int N = ;
int n, m;
int v[N][N], w[N][N], s[N];
int f[N];
int main() {
cin >> n >> m;
for (int i = ; i <= n; i ++ ) {
cin >> s[i];
for (int j = ; j < s[i]; j ++ )
cin >> v[i][j] >> w[i][j];
}
for (int i = ; i <= n; i ++ )
for (int j = m; j >= ; j -- )
for (int k = ; k < s[i]; k ++ )
if (v[i][k] <= j)
f[j] = max(f[j], f[j - v[i][k]] + w[i][k]);
cout << f[m] << endl;
return ;
}
//01背包的变种
#include <iostream>
#include <algorithm>
using namespace std;
const int N = ;
int n, m;
int v[N], w[N];
int f[N];
int main() {
cin >> n >> m;
for (int i = ; i < n; i ++ ) {
int s;
cin >> s;
for (int j = ; j < s; j ++ ) cin >> v[j]>>w[j];
for (int j = m ; j >=; j --)
for(int k = ; k<s; k++)
if(j>=v[k])
f[j]=max(f[j],f[j-v[k]]+w[k]);
}
cout << f[m] << endl;
return ;
}

AcWing 9. 分组背包问题的更多相关文章

  1. 动态规划:HDU1712-ACboy needs your help(分组背包问题)

    ACboy needs your help Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

  2. ACboy needs your help hdu 分组背包问题

    Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,t ...

  3. AcWing 6. 多重背包问题 III

    //f[i,j] 所有只从前i块能量石中选,且总体积恰好为j的方案数 #include <iostream> #include <algorithm> #include < ...

  4. AcWing 7. 混合背包问题

    #include<iostream> #include<algorithm> #include<cstring> using namespace std ; ; i ...

  5. AcWing 5. 多重背包问题 II

    //二进制优化 最后变为01背包 #include <iostream> #include <algorithm> using namespace std; , M = ; i ...

  6. AcWing 3. 完全背包问题

    朴素 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; int v[N],w[N] ...

  7. AcWing 4. 多重背包问题

    朴素 数据范围小 //数据范围小 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; ...

  8. AcWing 2. 01背包问题

    朴素 //朴素二维 #include <iostream> #include <algorithm> using namespace std; ; int n, m; int ...

  9. acwing 4 多重背包问题 I

    多重背包 有 n种物品 一共有 m大小的背包,每种物品的价值 大小 个数 为 s[i],v[i],num[i]; #include<bits/stdc++.h>//cmhao #defin ...

随机推荐

  1. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  2. vue动画&过渡整理

  3. [PAT] A1021 Deepest Root

    [题目大意] 给出n个结点和n-1条边,问它们能否形成一棵n个结点的树,如果能,从中选出结点作为树根,使整棵树的高度最大.输出所有满足要求的可以作为树根的结点. [思路] 方法一:模拟. 1 连通.边 ...

  4. MySQL的数据库备份

    MySQL的数据库备份 备份的原因: 1.保证重要数据不丢失 2.数据转移 MySQL数据库备份方式: 1.方法1:在Sqlyog这种可视化工具中手动导出 2.方法2:直接拷贝物理文件(就是data文 ...

  5. 1.(group by)如何让group by分组后,每组中的所有数据都显示出来

    问题描述:表如下,如何让这个表按device_id这个字段分组,且组中的每条数据都查寻出来?(假如说这个表名为:devicedata) 错误答案:select * from devicedata GR ...

  6. 将Ubuntu软件更新的源,换城阿里源

    阿里云镜像: https://developer.aliyun.com/mirror/ 简介 Ubuntu,是一款基于 Debian Linux 的以桌面应用为主的操作系统,内容涵盖文字处理.电子邮件 ...

  7. pandas玩转excel-> (1)如何利用pandas创建excel数据文件

    #在Anaconda3 的Spyder中   #定义pandas模块为pd import pandas as pd   #创建一个新的DataFrame对象,定义这个对象中有两个字段:ID和Name, ...

  8. MarkDown图文编辑系列教程(二)

    一.写在前面 引言 本文是我写的MarkDown系列教程的第二篇,前一篇的地址:MarkDown图文编辑系列教程(一) 读完本篇,你将获得 学会使用markdown语法进行:区块引用(一种常用的引用格 ...

  9. Blue Jeans[poj3080]题解

    题目 Description - The Genographic Project is a research partnership between IBM and The National Geog ...

  10. ubuntu安装pyenv

    安装依赖包 bash {.line-numbers} sudo apt-get update sudo apt-get install build-essential python-dev pytho ...