当前位置:网站首页>[niuke.com] dp31 [template] complete Backpack
[niuke.com] dp31 [template] complete Backpack
2022-06-11 21:48:00 【When the flower does not wither】

The output of the first line is a typical complete knapsack problem , And the second line is that the volume is required to be fixed with the maximum value , Therefore, we need to dp2 Initialize to int The minimum value that a type can express , And will dp2[ 0 ] The assignment is 0.
#include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
const int N = 1000 + 10;
int v[N], w[N], dp1[N], dp2[N];
int main(){
int n, m;
while(scanf("%d%d", &n, &m) != EOF){
for(int i = 0; i < n; i++) scanf("%d%d", &w[i], &v[i]);
fill(dp2, dp2 + m + 1, -INT_MAX);
dp2[0] = 0;
for(int i = 0; i < n; i++){
for(int j = w[i]; j <= m; j++){
dp1[j] = max(dp1[j], dp1[j - w[i]] + v[i]);
dp2[j] = max(dp2[j], dp2[j - w[i]] + v[i]);
}
}
printf("%d\n", dp1[m]);
if(dp2[m] < 0) printf("0\n");
else printf("%d\n", dp2[m]);
}
return 0;
}
边栏推荐
猜你喜欢
随机推荐
How to import workflows provided on SAP API hub to sap BTP
LabVIEW controls Arduino to realize infrared ranging (advanced chapter-6)
go io模块
How to use the transaction code sat to find the name trial version of the background storage database table corresponding to a sapgui screen field
How to create the simplest SAP kyma function
Jenkins+allure integrated report construction
RPA丨首席财务官如何找到数字化转型“超级入口”?
Carry and walk with you. Have you ever seen a "palm sized" weather station?
Codeworks round 744 (Div. 3) problem solving Report
go encoding包
Customer information management software
Leetcode-322- change exchange
[v2.1] automatic update system based on motion step API (repair bug, increase completion display, support disconnection reconnection and data compensation)
R语言书籍学习03 《深入浅出R语言数据分析》-第八章 逻辑回归模型 第九章 聚类模型
Leetcode-32- longest valid bracket
Introduction à endnotex9 et instructions pour les tutoriels de base
238.除自身以外数组的乘积
LeetCode-32-最长有效括号
189. rotation array
LaTex实战笔记 3-宏包与控制命令









