当前位置:网站首页>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;
//}
边栏推荐
- 树莓派 的 arm 版的 gcc 安装 和环境变量的配置
- TypeScript simplifies running ts-node
- Difference Between Compiled and Interpreted Languages
- 如何下载Keil包
- Hackers can how bad to what degree?
- button remove black frame
- opencv 缩小放大用哪种插值更好??
- Compiled on unbutu with wiringPi library and run on Raspberry Pi
- Advice given by experts with four years of development experience in Flutter tutorial
- Error using ts-node
猜你喜欢
Introduction to the Elastic Stack
剑指offer专项突击版第16天
win10 固定本机IP
HCIP(15)
button去除黑框
Unknown Bounded Array
Make your Lottie support word wrapping in text fields
[Search topic] After reading the inevitable BFS solution to the shortest path problem
Replacing the Raspberry Pi Kernel
【Make YOLO Great Again】YOLOv1-v7全系列大解析(Neck篇)
随机推荐
This article takes you to understand the past and present of Mimir, Grafana's latest open source project
普通用户无法访问hgfs目录
[SemiDrive source code analysis] series article link summary (full)
Step by step hand tearing carousel Figure 3 (nanny level tutorial)
Soft Exam Senior System Architect Series: Basic Knowledge of Information Systems
Nmap manuals - the full version
移动端页面秒开优化总结
Character encoding and floating point calculation precision loss problem
【 Make YOLO Great Again 】 YOLOv1 v7 full range with large parsing (Neck)
HCIP(15)
pdb药物综合数据库
button去除黑框
Summary of mobile page optimization in seconds
Game Theory (Depu) and Sun Tzu's Art of War (42/100)
Game Security 03: A Simple Explanation of Buffer Overflow Attacks
The device node structure is converted into a platform_device structure
Chain programming, packages, access
Replacing the Raspberry Pi Kernel
Article summary: the basic model of VPN and business types
更换树莓派内核