当前位置:网站首页>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;
//}
边栏推荐
- After specifying set 'execution.savepoint.path', restart flinksql and report this error
- What is a programming language
- Replacing the Raspberry Pi Kernel
- IDEA debugging
- 使用ts-node报错
- 项目越写越大,我是这样做拆分的
- Basic usage concepts of vim
- HCIP(15)
- Soft Exam Senior System Architect Series: Basic Knowledge of Information Systems
- Elastic Stack的介绍
猜你喜欢
【uniCloud】云对象的应用与提升
Unknown Bounded Array
[Message Notification] How about using the official account template message?
预言机简介
[Search topic] After reading the inevitable BFS solution to the shortest path problem
win10 固定本机IP
A way to deal with infinite debugger
"ArchSummit: The cry of the times, technical people can hear"
HIRO: Hierarchical Reinforcement Learning 】 【 Data - Efficient Hierarchical Reinforcement Learning
Game Security 03: A Simple Explanation of Buffer Overflow Attacks
随机推荐
This map drawing tool is amazing, I recommend it~~
Write a method to flatten an array and deduplicate and sort it incrementally
Basic use of vim - command mode
MySQL3
每周小结(*67):为什么不敢发表观点
leetcode6133. 分组的最大数量(中等)
Software Testing Interview (3)
项目越写越大,我是这样做拆分的
lua entry case combat 123DIY
Flutter Tutorial 01 Configure the environment and run the demo program (tutorial includes source code)
A way to deal with infinite debugger
2. # 代码注释
Solve the problem that Excel opens very slowly after installing MySQL
IDEA does not recognize the module (there is no blue square in the lower right corner of the module)
【入门教程】Rollup模块打包器整合
The fledgling Xiao Li's 113th blog project notes: Wisdom cloud smart flower watering device combat (2) - basic Demo implementation
button remove black frame
【 Make YOLO Great Again 】 YOLOv1 v7 full range with large parsing (Neck)
情人节浪漫3D照片墙【附源码】
Game Security 03: A Simple Explanation of Buffer Overflow Attacks