当前位置:网站首页>Dynamic programming -- knapsack problem
Dynamic programming -- knapsack problem
2022-07-06 05:53:00 【Lin Shiliu should work hard】
f[i][j] Once upon a time i A selection of items , The volume is not greater than j Maximum value of
1. 01 knapsack
int f[N][M];
int dp()
{
for(int i=1;i<=n;i++)
for(int j=0;j<=m;j++)
{
f[i][j]=f[i-1][j];
if(j>=v[i])
f[i][j]=max(f[i][j],f[i-1][j-v[i]]+w[i]);
}
return f[n][m];
} int f[M];
int dp()
{
for(int i=0;i<=n;i++)
for(int j=m;j>=v[i];j--)
f[j]=max(f[j],f[j-v[i]]+w[i]);
return f[m];
} 2. Completely backpack
Completely backpacking Same layer status to update , Compress to One dimensional positive sequence update
int f[N][M];
int dp()
{
for(int i=1;i<=n;i++)
for(int j=0;j<=m;j++)
{
f[i][j]=f[i-1][j];
if(j>=v[i])边栏推荐
- Redis message queue
- LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
- How to get list length
- AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
- Processes and threads
- Text classification still stays at Bert? The dual contrast learning framework is too strong
- H3C firewall rbm+vrrp networking configuration
- Mysql database master-slave cluster construction
- 29io stream, byte output stream continue write line feed
- Selective parameters in MATLAB functions
猜你喜欢

养了只小猫咪

Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method

MIT6.s081-2020 Lab2 System Calls

Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist

【无标题】

【论文阅读】NFlowJS:基于鲁棒学习的合成负数据密集异常检测

大型网站如何选择比较好的云主机服务商?

ArcGIS应用基础4 专题图的制作

【论文代码】SML部分代码阅读
![[Tang Laoshi] C -- encapsulation: classes and objects](/img/4e/30d2d4652ea2d4cd5fa7cbbb795863.jpg)
[Tang Laoshi] C -- encapsulation: classes and objects
随机推荐
Text classification still stays at Bert? The dual contrast learning framework is too strong
Problems encountered in installing mysql8 on MAC
What is independent IP and how about independent IP host?
Some easy-to-use tools make your essay style more elegant
局域网同一个网段通信过程
How to get list length
Station B Liu Erden - linear regression and gradient descent
[happy Spring Festival] if you feel happy, dance
[force buckle]43 String multiplication
Closure, decorator
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
Download, install and use NVM of node, and related use of node and NRM
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
[email protected] raspberry pie
Pay attention to the details of pytoch code, and it is easy to make mistakes
实践分享:如何安全快速地从 Centos迁移到openEuler
Mysql database master-slave cluster construction
查询生产订单中某个(些)工作中心对应的标准文本码
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
C language bubble sort