当前位置:网站首页>Dynamic Programming 01 Backpack
Dynamic Programming 01 Backpack
2022-08-01 03:55:00 【Lucky for nine years】
01I believe my friends know the backpack.
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
int all , n, w[105], v[105], ans[105][1000005];
int main() {
cin >> all >> n;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= all; j++) {
if (j < w[i]) {
ans[i][j] = ans[i - 1][j];
} else {
ans[i][j] = max(ans[i- 1][j], ans[i - 1][j - w[i]] + v[i]);
}
}
}
cout << ans[n][all] << endl;
return 0;
}
//int main() {
// ios::sync_with_stdio(false); //虽然ios::sync_with_stdio对cin有加速所用,但是还是没有scanf的速度快.
// cin >> all >> n;
// for (int i = 1; i <= n; i++) {
// cin >> w[i] >> v[i];
// }
// for (int i = 1; i <= n; i++ ){
// for (int j = all; j <= w[i]; j--) {
// ans[j] = max(ans[j], v[i] + ans[j - w[i]]);
// }
// }
// cout << ans[all] << endl;
// return 0;
//}
边栏推荐
- button remove black frame
- 785. Quick Sort
- JS new fun(); class and instance JS is based on object language Can only act as a class by writing constructors
- HIRO: Hierarchical Reinforcement Learning 】 【 Data - Efficient Hierarchical Reinforcement Learning
- 【kali-信息收集】枚举——DNS枚举:DNSenum、fierce
- lua entry case combat 123DIY
- The 16th day of the special assault version of the sword offer
- Elastic Stack的介绍
- IDEA does not recognize the module (there is no blue square in the lower right corner of the module)
- The fledgling Xiao Li's 114th blog project notes: Wisdom cloud intelligent flower watering device combat (3) - basic Demo implementation
猜你喜欢
纽约大学等 | TM-Vec:用于快速同源检测和比对的模版建模向量
Software Testing Weekly (Issue 82): In fact, all those who are entangled in making choices already have the answer in their hearts, and consultation is just to get the choice that they prefer.
The fledgling Xiao Li's 113th blog project notes: Wisdom cloud smart flower watering device combat (2) - basic Demo implementation
树莓派 的 arm 版的 gcc 安装 和环境变量的配置
[Search topic] After reading the inevitable BFS solution to the shortest path problem
【搜索专题】看完必会的BFS解决最短路问题攻略
Article summary: the basic model of VPN and business types
second uncle
Four implementations of
batch insert: have you really got it? Elastic Stack的介绍
随机推荐
ARM cross compilation
【 Make YOLO Great Again 】 YOLOv1 v7 full range with large parsing (Neck)
How is the tree structure of the device tree reflected?
Completely closed Chrome updated and in the top right corner of the tip
The fledgling Xiao Li's 112th blog project notes: Wisdom cloud intelligent flower watering device actual combat (1) - basic Demo implementation
pdb drug comprehensive database
软件测试周刊(第82期):其实所有纠结做选择的人心里早就有了答案,咨询只是想得到内心所倾向的选择。
Unknown Bounded Array
leetcode6133. 分组的最大数量(中等)
Guys, MySQL cdc source recycles replication slave and r in incremental process
《少年派2》:新男友竟脚踩两只船,林妙妙与钱三一感情回温
TypeScript simplifies running ts-node
785. Quick Sort
"Youth Pie 2": The new boyfriend stepped on two boats, and the relationship between Lin Miaomiao and Qian Sanyi warmed up
[SemiDrive source code analysis] series article link summary (full)
MySQL修改SQL语句优化性能
IDEA modifies the annotation font
Device tree - conversion from dtb format to struct device node structure
787. 归并排序
Game Security 03: A Simple Explanation of Buffer Overflow Attacks