#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. C++->输入输出文件流的相关函数

    标准输入输出流与文件输入输出流的关系图: 文件输出流头文件“ofstream/fstream”,文件输入流头文件“ifstream/fstream” 1.1.打开文件方式:流类 对象名(文件名,方式) ...

  2. Spring Cloud feign使用okhttp3

    指南 maven <dependency> <groupId>io.github.openfeign</groupId> <artifactId>fei ...

  3. 洛谷【P5004 专心OI - 跳房子】 题解

    题目链接 https://www.luogu.org/problem/P5004 洛谷 P5004 专心OI - 跳房子 Imakf有一天参加了PINO 2017 PJ组,他突然看见最后一道题 他十分 ...

  4. C++野指针的存在方式和误区

    1. char* x;这样的一定是野指针,指针声明时要直接初始化!或者置null也行! 2. int main() { char *x=new char; delete x; cout<< ...

  5. .Net Core 智能提示汉化包

    在.Net Core 2.x 版本,Microsoft 官方没有提供 .Net Core 正式版的多语言安装包.因此,我们在用.Net Core 2.x 版本作为框架目标编写代码时,智能提成是英文的. ...

  6. html中引入调用另一个html文件

    第一种: <body> <div id="page1"></div> <div id="page2"></ ...

  7. 实用沙盒工具 —— VMware Workstation15安装教程

    一:简介 VMware Workstation(中文名"威睿工作站")是一款功能强大的桌面虚拟计算机软件,提供用户可在单一的桌面上同时运行不同的操作系统,和进行开发.测试 .部署新 ...

  8. Wannafly Camp 2020 Day 6K 最大权值排列

    按照样例那样排列即可 #include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; if( ...

  9. try_except_finally

    blog: python中的try/except/else/finally  python文档:错误和异常 与其他语言相同,在python中,try/except语句主要是用于处理程序正常执行过程中出 ...

  10. 使用Vmware过程中,突然网络连接不上问题

    ###第一次的解决方法: 1.我一般过一段时间就会对虚拟机进行拍快照备份:在使用过程中,如果没有太大变化,恢复网络正常的快照一般是能解决问题的,但是要记得恢复快照之前要备份你已经修改过的所有东西,以防 ...