当前位置:网站首页>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])
边栏推荐
- 网络协议模型
- C language learning notes (mind map)
- [SQL Server fast track] - authentication and establishment and management of user accounts
- [Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
- Construction of yolox based on paste framework
- Embedded interview questions (IV. common algorithms)
- [imgui] unity MenuItem shortcut key
- P2802 go home
- Report on market depth analysis and future trend prediction of China's arsenic trioxide industry from 2022 to 2028
- Analysis of grammar elements in turtle Library
猜你喜欢
PDK工藝庫安裝-CSMC
[Jiudu OJ 07] folding basket
What preparations should be made for website server migration?
H3C V7版本交换机配置IRF
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
ArcGIS application foundation 4 thematic map making
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
Installation de la Bibliothèque de processus PDK - csmc
什么是独立IP,独立IP主机怎么样?
Garbage collector with serial, throughput priority and response time priority
随机推荐
Selective parameters in MATLAB functions
Station B, Master Liu Er - back propagation
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
Quantitative description of ANC noise reduction
Garbage collector with serial, throughput priority and response time priority
Text classification still stays at Bert? The dual contrast learning framework is too strong
The usage and difference between strlen and sizeof
H3C防火墙RBM+VRRP 组网配置
[experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
大型网站如何选择比较好的云主机服务商?
Redistemplate common collection instructions opsforvalue (II)
B站刘二大人-反向传播
【课程笔记】编译原理
27io stream, byte output stream, OutputStream writes data to file
初识数据库
Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
养了只小猫咪
High quality coding tool clion
Summary of data sets in intrusion detection field