当前位置:网站首页>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])
边栏推荐
- [paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
- Construction of yolox based on paste framework
- Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
- Summary of data sets in intrusion detection field
- [string] palindrome string of codeup
- Pay attention to the details of pytoch code, and it is easy to make mistakes
- Network protocol model
- Classes and objects (I) detailed explanation of this pointer
- 局域网同一个网段通信过程
- Rustdesk builds its own remote desktop relay server
猜你喜欢
YYGH-11-定时统计
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
LAN communication process in the same network segment
Construction of yolox based on paste framework
什么是独立IP,独立IP主机怎么样?
[SQL Server fast track] - authentication and establishment and management of user accounts
Processes and threads
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
Raised a kitten
CoDeSys note 2: set coil and reset coil
随机推荐
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
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
局域网同一个网段通信过程
Raised a kitten
Selective parameters in MATLAB functions
After the project is released, index Html is cached
First knowledge database
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
P2802 go home
[SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
Yunxiaoduo software internal test distribution test platform description document
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
嵌入式面试题(四、常见算法)
Installation de la Bibliothèque de processus PDK - csmc
网站进行服务器迁移前应做好哪些准备?
B站刘二大人-反向传播
As3013 fire endurance test of cable distribution system
B站刘二大人-线性回归及梯度下降
实践分享:如何安全快速地从 Centos迁移到openEuler