当前位置:网站首页>背包问题 AcWing 9. 分组背包问题
背包问题 AcWing 9. 分组背包问题
2022-07-27 10:35:00 【T_Y_F666】
背包问题 AcWing 9. 分组背包问题
原题链接
算法标签
背包问题 DP
思路

代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 105;
int s[N];
int v[N][N], w[N][N],f[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read(), vv=read();
rep(i, 1, n+1){
s[i]=read();
rep(j, 0, s[i]){
v[i][j]=read(), w[i][j]=read();
}
}
// n组物品
rep(i, 1, n+1){
// 背包剩余容量 由于物品只能使用一次 因此从大到小循环
Rep(j, vv, 0){
// 第i组中选取一个物品使价值最大
rep(k, 0, s[i]){
if(v[i][k]<=j){
f[j]=max(f[j], f[j-v[i][k]]+w[i][k]);
}
}
}
}
printf("%lld", f[vv]);
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 数字三角形模型 AcWing 275. 传纸条
- 2022牛客多校训练(3)A-Ancestor 题目翻译
- Miscellaneous records of Finance
- Shortest moving distance and entropy of morphological complex
- 最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
- c语言指针函数和函数指针的辨析
- Li Hongyi_ Machine learning_ Assignment 4 (detailed explanation)_ HW4 Classify the speakers
- [QNX Hypervisor 2.2用户手册]9.9 logger
- JVM judges that the object is dead, and practices verify GC recycling
- Overview of data security in fog computing
猜你喜欢

The influence of the number of non-zero values in the picture on Classification

XXX packages are looking for funding run 'NPM fund' for details solutions

熵与形态的非递进现象

Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)

数字三角形模型 AcWing 275. 传纸条

The open source project Taier version 1.1 was officially released, and the list of new functions is fast

Yiwen counts NFT projects valued at more than US $100million

Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen

MySQL installation (RPM package)

推导STO双中心动能积分的详细展开式
随机推荐
最长上升子序列模型 AcWing 482. 合唱队形
antd中table hover上去的背景色样式修改
Antd table+checkbox default value display
10 complete half of the questions
IO stream_ Character stream, IO stream summary, IO stream case summary
A measurement method of 5g air interface one-way delay and its reliability
9 UAV array
SQL Server2000数据库错误
Substr and substring function usage in SQL
学习笔记-简易服务器实现
Play with the cluster configuration center and learn about the Taier console
最短移动距离和形态复合体的熵
6 find the smallest letter larger than the target letter
MySQL installation (RPM package)
tensorflow运行报错解决方法
最长上升子序列模型 AcWing 1014. 登山
Redis+caffeine two-level cache enables smooth access speed
树形数据转换
Tree data conversion
Application of 5g private network in smart medicine