当前位置:网站首页>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])边栏推荐
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
- How to download GB files from Google cloud hard disk
- AUTOSAR from getting started to becoming proficient (10) - embedded S19 file analysis
- Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
- Application Security Series 37: log injection
- Go language -- language constants
- 如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
- P2802 go home
- Garbage collector with serial, throughput priority and response time priority
- [imgui] unity MenuItem shortcut key
猜你喜欢

Grant Yu, build a web page you want from 0

Application Security Series 37: log injection

数字经济破浪而来 ,LTD是权益独立的Web3.0网站?

First knowledge database

What impact will frequent job hopping have on your career?

Analysis of grammar elements in turtle Library

Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
![[Tang Laoshi] C -- encapsulation: classes and objects](/img/4e/30d2d4652ea2d4cd5fa7cbbb795863.jpg)
[Tang Laoshi] C -- encapsulation: classes and objects

类和对象(一)this指针详解

初识数据库
随机推荐
[paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
What is independent IP and how about independent IP host?
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
通讯录管理系统链表实现
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
应用安全系列之三十七:日志注入
Implementation of linked list in address book management system
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
[Tang Laoshi] C -- encapsulation: classes and objects
Redis消息队列
Query the standard text code corresponding to a work center (s) in the production order
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
C language learning notes (mind map)
实践分享:如何安全快速地从 Centos迁移到openEuler
OSPF configuration command of Huawei equipment
局域网同一个网段通信过程
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
【无标题】
After the project is released, index Html is cached