当前位置:网站首页>背包问题 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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Use of pyquery
- What is the mystery of the gate of the meta universe?
- Self optimization of wireless cell load balancing based on machine learning technology
- 最短移动距离和形态复合体的熵
- 推导STO双中心动能积分的详细展开式
- 学习笔记-minio
- XXX packages are looking for funding run 'NPM fund' for details solutions
- How to build a data index system is the most effective. It will take you a quick start from 0 to 1
- 49字母异位分组和242有效的字母异位词
- C language 2: find the maximum value of three numbers, find the middle value of three numbers, and write program steps
猜你喜欢

图片中非0值的数量对分类的影响

Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education

ethereum rpc

迭代次数的差异与信息熵

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

KEPServer配置

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

49字母异位分组和242有效的字母异位词

如何创建一个带诊断工具的.NET镜像

Influence of black and white pixel distribution on iteration times
随机推荐
Opengauss kernel analysis - statistics and row count estimation
最长上升子序列模型 AcWing 1010. 拦截导弹
9 UAV array
A verification test of the relationship between iteration number and entropy
parsel的使用
Time and power allocation method to ensure fairness in sensor fusion system
黑白像素分布对迭代次数的影响
Students, don't copy all my code, remember to change it, or we both want G
349两个数组的交集和01两数之和
Maximized array sum after 13 K negations
Yiwen counts NFT projects valued at more than US $100million
Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
MIMO array 3D imaging technology based on mobile terminal
Yum source installation
正则form表单判断
Derive the detailed expansion of STO double center kinetic energy integral
IO stream_ Character stream, IO stream summary, IO stream case summary
Use of pyquery
Cancer DDD
IO stream_ Overview and explanation of data input and output flow