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 ...
随机推荐
- Java连载86-List集合详解
一.List集合 1.List集合存储元素的特点: (1)有序(List集合中存储有下标):存进去是这样的顺序,取出来还是按照这个顺序取出. (2)可重复 2.深入ListJ集合 ArrayLis ...
- Cobalt Strike配置及简单使用
前言 CS分为客户端与服务端,服务端是一个,客户端可以有多个,非常适合团队协同作战,多个攻击者可以同时连接到一个团队服务器上,共享攻击资源与目标信息和sessions,可模拟APT做模拟对抗,进行内网 ...
- Zjnu Stadium HDU - 3047 带权并查集板子题
#include<iostream> #include<cstring> #include<cstdio> using namespace std; +; int ...
- QS Network ZOJ - 1586 板子题
#include<iostream> #include<algorithm> using namespace std; ; struct edge{ int a,b; doub ...
- cartographer保存地图
手持激光,并用cartographer建图,保存的地图是.pbstream格式 ht@ht:~$ rosservice call /write_state /home/ht/Desktop/carto ...
- ip连接mysql时报不能连接
问题:springboot项目在用localhost连接mysql时没问题,但当localhost换成ip时出现 该问题:message from server: "Host 'DESKTO ...
- BZOJ3172&&lg3966 TJOI单词(广义后缀自动机)
BZOJ3172&&lg3966 TJOI单词(广义后缀自动机) 题面 自己找去 HINT 给出多个文本串,让你查找每个文本串一共出现了多少次,广义后缀自动机建出parent tree ...
- Linux shell unzip和tar 批量解压文件
#!/bin/sh UNTAR="tar -xvf " #unzip all zip files function unzip_all_file() { for i in *.zi ...
- H5_0011:JS动态创建html并设置CSS属性
1,创建html文本,并设置指定css样式 r = function(e) { var t = document.createElement("div"); t.innerHTML ...
- ZedGraph怎样实现将图形右键菜单的打印和页面设置合并为打印的二级子菜单
场景 Winforn中实现ZedGraph自定义添加右键菜单项(附源码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...