当前位置:网站首页>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 
边栏推荐
- 论文阅读报告
- Leetcode backtracking method
- Paper reading report
- MySQL advanced part 1: index
- LeetCode 1200. Minimum absolute difference
- 1.14 - assembly line
- Applicable to Net free barcode API [off] - free barcode API for NET [closed]
- MySQL advanced part 2: storage engine
- Leetcode divide and conquer / dichotomy
- 4. Object mapping Mapster
猜你喜欢

Traditional databases are gradually "difficult to adapt", and cloud native databases stand out

Find the combination number acwing 887 Find combination number III

WordPress switches the page, and the domain name changes back to the IP address

Operator priority, one catch, no doubt

What is socket? Basic introduction to socket

4. Oracle redo log file management

5. Oracle TABLESPACE

Client use of Argo CD installation

1.13 - RISC/CISC

Gauss Cancellation acwing 884. Solution d'un système d'équations Xor linéaires par élimination gaussienne
随机推荐
[learning] database: MySQL query conditions have functions that lead to index failure. Establish functional indexes
MySQL advanced part 2: the use of indexes
3. Oracle control file management
Leetcode-6111: spiral matrix IV
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
论文阅读报告
时间很快,请多做有意义的事情
Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
Leetcode-31: next spread
What's wrong with this paragraph that doesn't work? (unresolved)
博弈论 AcWing 894. 拆分-Nim游戏
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
5. Oracle tablespace
International Open Source firmware Foundation (osff) organization
MySQL advanced part 2: optimizing SQL steps
Leetcode-1200: minimum absolute difference
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
Redis publish subscribe command line implementation
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库