#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. HTML连载65-过渡模块的基本使用

    一.过渡模块的基本使用 1.*:hover;这个伪类选择器除了可以用在a标签上,还可以用在其他任何标签上. 2.过渡三要素: (1)必须要有属性发生变化:(2)必须告诉系统哪个属性需要执行过渡效果:( ...

  2. 【JavaScript】JS总结 – 乱

    一. 重要:js中的function函数声明.函数表达式 // 函数声明 // Ex: 会在代码执行之前提前加载到作用域中,即js解析器会优先读取,确保在所有代码执行之前声明已经被解析:所以可以在定义 ...

  3. [PAT] A1022 Digital Library

    [题目大意] 给出几本书的信息,包括编号,名字,出版社,作者,出版年份,关键字:然后给出几个请求,分别按照1->名字,2->出版社等对应信息查询符合要求的书的编号. [思路] 模拟. [坑 ...

  4. 字符串积累ing

    明天就要上网课拉拉啦啦! 数据库先在手机端登录然后转战客户端试之! 操作系统在客户端登录试一试! 马原用学习通试试啦! 首先,介绍一下strlen,strcpy,strcmp函数! 参考:https: ...

  5. python3练习100题——054

    题目:取一个整数a从右端开始的4〜7位. a=input('please input a num:') print(a[-7:-3])

  6. 使用nohup不产生log文件方法

    思想 无法阻止nohup产生日志可以将其定向到空文件实现 实现 $ nohup xxx >/dev/null 2>&1 &

  7. 怎么压缩PPT大小?

    PPT体积过大有几个原因: 1.母版内版式过多.解决方法:①点击“视图”选项卡下的“幻灯片母版”:②删除左边没必要的版式. 2.图片质量太大.解决方法:①选中任意一张图片:②点击“图片工具”的“格式” ...

  8. 从0开始学算法--排序(1.12c++利用标准库排序)

    1,简单数组按升序排序 sort(a,a+n); #include <algorithm> #include <iostream> #include <cstring&g ...

  9. 【你不知道的javaScript 上卷 笔记5】javaScript中的this词法

    function foo() { console.log( a ); } function bar() { var a = 3; foo(); } var a = 2; bar(); 上面这段代码为什 ...

  10. eclipse调字体大小

    首先调java字体: Window -> Preferences -> General -> Appearance -> Colors and Fonts -> Java ...