AcWing 9. 分组背包问题
#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. 分组背包问题的更多相关文章
- 动态规划:HDU1712-ACboy needs your help(分组背包问题)
ACboy needs your help Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- 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 ...
- AcWing 6. 多重背包问题 III
//f[i,j] 所有只从前i块能量石中选,且总体积恰好为j的方案数 #include <iostream> #include <algorithm> #include < ...
- AcWing 7. 混合背包问题
#include<iostream> #include<algorithm> #include<cstring> using namespace std ; ; i ...
- AcWing 5. 多重背包问题 II
//二进制优化 最后变为01背包 #include <iostream> #include <algorithm> using namespace std; , M = ; i ...
- AcWing 3. 完全背包问题
朴素 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; int v[N],w[N] ...
- AcWing 4. 多重背包问题
朴素 数据范围小 //数据范围小 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; ...
- AcWing 2. 01背包问题
朴素 //朴素二维 #include <iostream> #include <algorithm> using namespace std; ; int n, m; int ...
- acwing 4 多重背包问题 I
多重背包 有 n种物品 一共有 m大小的背包,每种物品的价值 大小 个数 为 s[i],v[i],num[i]; #include<bits/stdc++.h>//cmhao #defin ...
随机推荐
- ng-模板语法
插值 文本绑定 <p>Message: {{ msg }}</p> <p [innerHTML]="msg"></p> 属性绑定 & ...
- 双向链表的简单Java实现-sunziren
写在前面,csdn的那篇同名博客就是我写的,我把它现在在这边重新发布,因为我实在不想用csdn了,那边的广告太多了,还有就是那个恶心人的“阅读更多”按钮,惹不起我躲得起. 在上次分享完单向链表的简单编 ...
- Log4net实用说明
Log4net实用说明 Appender Filter Layout Logger ObjectRender Repository PatterLayout格式化字符表 配置文件说明 Appender ...
- .NetCore学习笔记:三、基于AspectCore的AOP事务管理
AOP(面向切面编程),通过预编译方式和运行期间动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是函数式编程的一种衍生范型.利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑 ...
- LeetCode 3sum-closest 题解
思路 排序 枚举一个数a 双指针移动法确定b和c 求和,更新最接近的值 复杂度 T(n)=O(n2)  M(n)=O(1)T(n)=O(n^2) \; M(n)=O(1)T ...
- react 事件传参数
class Demo extends React.Component { click = (a) => (e) => { console.log('额鹅鹅鹅', a, e); } rend ...
- 转载:openmax bellagio
https://wenku.baidu.com/view/18472c1387c24028915fc3e9.html https://wenku.baidu.com/view/1e380bc20c22 ...
- main中的argv和argc
int main(int argc,char* argv[]) 给程序传递命令行参数:第一个参数的值是第二个参数的数组元素个数,即统计运行程序时送给main函数的命令行参数个数. 第二个参数总是cha ...
- Xlrd模块读取Excel文件数据
Xlrd模块使用 excel文件样例:
- 全面了解 Java 原子变量类
目录 一.原子变量类简介 二.基本类型 三.引用类型 四.数组类型 五.属性更新器类型 参考资料