当前位置:网站首页>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;
//}
边栏推荐
- 787. Merge Sort
- Raspberry pie arm version of GCC installed configuration and environment variables
- Ordinary users cannot access HGFS directory
- How to download the Keil package
- The kernel of the decompression process steps
- [uniCloud] Application and Improvement of Cloud Objects
- opencv 缩小放大用哪种插值更好??
- pdb药物综合数据库
- Interview Blitz 69: Is TCP Reliable?Why?
- Advice given by experts with four years of development experience in Flutter tutorial
猜你喜欢

Browser download shortcut to desktop (PWA)

MySQL4

IDEA does not recognize the module (there is no blue square in the lower right corner of the module)

Ordinary users cannot access HGFS directory
![[Message Notification] How about using the official account template message?](/img/4d/5b47722d1f5ec1cae73fc8d930a35d.jpg)
[Message Notification] How about using the official account template message?

树莓派 的 arm 版的 gcc 安装 和环境变量的配置

MySQL4

【消息通知】用公众号模板消息怎么样?

Hackers can how bad to what degree?

Article summary: the basic model of VPN and business types
随机推荐
普通用户无法访问hgfs目录
787. Merge Sort
内核的解压缩过程详解
HCIP(15)
初出茅庐的小李第113篇博客项目笔记之机智云智能浇花器实战(2)-基础Demo实现
Basic usage concepts of vim
【搜索专题】看完必会的BFS解决最短路问题攻略
Flutter “Hello world“ 程代码
指定set 'execution.savepoint.path'后,重启flinksql报这个错是啥
The device node structure is converted into a platform_device structure
Unity在BuildIn渲染管线下实现PlanarReflection的初级方法
纽约大学等 | TM-Vec:用于快速同源检测和比对的模版建模向量
Introduction to Oracle
Message Queuing Message Storage Design (Architecture Camp Module 8 Jobs)
简单易用的任务队列-beanstalkd
One service layer needs to call the other two service layers to obtain data and assemble it into the final data. The data is all lists. How to design the cache?
Completely closed Chrome updated and in the top right corner of the tip
初出茅庐的小李第114篇博客项目笔记之机智云智能浇花器实战(3)-基础Demo实现
Raspberry pie arm version of GCC installed configuration and environment variables
IDEA does not recognize the module (there is no blue square in the lower right corner of the module)