当前位置:网站首页>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])
边栏推荐
- [Jiudu OJ 07] folding basket
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- 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
- 实践分享:如何安全快速地从 Centos迁移到openEuler
- Installation de la Bibliothèque de processus PDK - csmc
- LTE CSFB process
- [JVM] [Chapter 17] [garbage collector]
- 类和对象(一)this指针详解
- How can large websites choose better virtual machine service providers?
- CoDeSys note 2: set coil and reset coil
猜你喜欢
B站刘二大人-反向传播
Raised a kitten
类和对象(一)this指针详解
B站刘二大人-线性回归 Pytorch
[SQL Server fast track] - authentication and establishment and management of user accounts
Download, install and use NVM of node, and related use of node and NRM
嵌入式面试题(四、常见算法)
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
H3C firewall rbm+vrrp networking configuration
C language learning notes (mind map)
随机推荐
[force buckle]43 String multiplication
Web Security (VI) the use of session and the difference between session and cookie
How can large websites choose better virtual machine service providers?
查詢生產訂單中某個(些)工作中心對應的標准文本碼
P2802 go home
Construction of yolox based on paste framework
Go language -- language constants
[experience] install Visio on win11
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
Grant Yu, build a web page you want from 0
局域网同一个网段通信过程
28io stream, byte output stream writes multiple bytes
Station B Liu Erden - linear regression and gradient descent
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
Closure, decorator
PDK工藝庫安裝-CSMC
实践分享:如何安全快速地从 Centos迁移到openEuler
[email protected] raspberry pie
网站进行服务器迁移前应做好哪些准备?
Database: ODBC remote access SQL Server2008 in oracel