当前位置:网站首页>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])
边栏推荐
- [SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
- First knowledge database
- [Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
- 华为路由器忘记密码怎么恢复
- HCIA复习
- Redistemplate common collection instructions opsforvalue (II)
- Web service connector: Servlet
- Installation de la Bibliothèque de processus PDK - csmc
- B站刘二大人-线性回归 Pytorch
- Web Security (VI) the use of session and the difference between session and cookie
猜你喜欢
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
移植InfoNES到STM32
What impact will frequent job hopping have on your career?
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
Station B, Master Liu Er - dataset and data loading
【论文代码】SML部分代码阅读
【无标题】
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
Clear floating mode
Analysis of grammar elements in turtle Library
随机推荐
YYGH-11-定时统计
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
J'ai un chaton.
Redis message queue
As3013 fire endurance test of cable distribution system
27io stream, byte output stream, OutputStream writes data to file
数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
Network protocol model
Go language -- language constants
Redistemplate common collection instructions opsforvalue (II)
【经验】UltralSO制作启动盘时报错:磁盘/映像容量太小
First knowledge database
Station B, Mr. Liu Er - multiple logistic regression, structure 7
Redis6 cluster setup
[force buckle]43 String multiplication
29io stream, byte output stream continue write line feed
ArcGIS应用基础4 专题图的制作
The difference and usage between continue and break
华为路由器忘记密码怎么恢复
What preparations should be made for website server migration?