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 ...
随机推荐
- MongoDB的批量查询条件进行批量更新数据
今天遇到这样一个场景:在Java中批量更新MongoDB数据,不过每次更新的条件有不一样,那如何有效地进行更新操作呢? 刚开始的时候,我是想到循环批量更新操作,即每一种查询条件进行一次批量更新过程,这 ...
- 手动部署:在eclipse导入web项目并更新包到本地部署
一.eclipse导入java web项目 1.file-import-git-next-clone URL-填写git上面的URL,然后一直next,完成后等待即可 二.导入多个版本项目 1.fil ...
- Joomla 3.0.0 --> 3.4.6-RCE复现
Joomla是一款网站管理系统CMS,最近曝出其3.00-3.4.6的joomla版本存在一个RCE漏洞. 并且大佬已将exp放在了github上,下载地址:https://www.exploit-d ...
- AMCL论文及源码解析--参数(持续更新中)
整理内容来自:http://wiki.ros.org/amcl 1.AMCL订阅的节点: scan (sensor_msgs/LaserScan):激光数据 tf (tf/tfMessage):各种转 ...
- 数位dp(模板+例题)
文章参考:数位dp之总结 首先,什么是数位dp?它是干什么的? 数位dp是一种计数用的dp,一般就是要统计一个区间[le,ri]内满足一些条件数的个数. 举个栗子: 加入我们要枚举所有上界不超过231 ...
- php 公众号开发
思考: 1,优先使用php扩展库的sdk,配合微信文档. 2,公众号开发比较简单,重在业务. 公众号关联与消息分发 <?php namespace app\wap\controller; use ...
- Hibernate 和Mybatis的区别
Hibernate 和Mybatis的区别 1.hibernate 入门门槛高,是一个标准的ORM框架(对象关系映射),不需要程序写sql,sql语句自动生成,对sql语句进行优化.修改比较困难. ...
- springboot项目集成activity
1.按照上一篇博客,新建好springboot项目后,在项目pom.xml文件中添加activity依赖 <dependency> <groupId>org.activiti& ...
- Wannafly Camp 2020 Day 1F 乘法 - 字符串
一开始想根据单调性双指针 后来血了才想起来负负得正 于是暴力二分答案即可 #include <bits/stdc++.h> using namespace std; #define int ...
- phpstorm 安装插件
进入 File -> Settings -> Plugins ,搜索你想要安装的插件