当前位置:网站首页>Knapsack problem acwing 9 Group knapsack problem
Knapsack problem acwing 9 Group knapsack problem
2022-07-05 06:24:00 【T_ Y_ F666】
knapsack problem AcWing 9. Group knapsack problem
Original link
AcWing 9. Group knapsack problem
Algorithm tags
knapsack problem DP
Ideas

Code
#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 Group items
rep(i, 1, n+1){
// The remaining capacity of the backpack Because items can only be used once So cycle from large to small
Rep(j, vv, 0){
// The first i Select an item in the group to maximize the value
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;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- 什么是套接字?Socket基本介绍
- 2048 project realization
- 在新线程中使用Handler
- There are three kinds of SQL connections: internal connection, external connection and cross connection
- Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
- Client use of Argo CD installation
- How to generate an image from text on fly at runtime
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- MySQL怎么运行的系列(八)14张图说明白MySQL事务原子性和undo日志原理
- 5. Oracle TABLESPACE
猜你喜欢

Leetcode-6108: decrypt messages

How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling

Paper reading report

TCP's understanding of three handshakes and four waves

容斥原理 AcWing 890. 能被整除的数

Sqlmap tutorial (1)

5. Oracle TABLESPACE

Leetcode-6110: number of incremental paths in the grid graph

1.13 - RISC/CISC

博弈论 AcWing 893. 集合-Nim游戏
随机推荐
MySQL advanced part 1: index
Usage scenarios of golang context
our solution
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
4. Object mapping Mapster
2021apmcm post game Summary - edge detection
Basic explanation of typescript
背包问题 AcWing 9. 分组背包问题
中国剩余定理 AcWing 204. 表达整数的奇怪方式
June 29, 2022 daily
Winter vacation water test 1 Summary
LeetCode 1200. Minimum absolute difference
Leetcode-6111: spiral matrix IV
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
P2575 master fight
Operator priority, one catch, no doubt
求组合数 AcWing 889. 满足条件的01序列
Alibaba established the enterprise digital intelligence service company "Lingyang" to focus on enterprise digital growth
高斯消元 AcWing 884. 高斯消元解异或線性方程組
博弈论 AcWing 891. Nim游戏