当前位置:网站首页>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])边栏推荐
- Embedded interview questions (IV. common algorithms)
- [Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS
- 嵌入式面试题(一:进程与线程)
- Embedded interview questions (I: process and thread)
- 【经验】UltralSO制作启动盘时报错:磁盘/映像容量太小
- Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
- 清除浮动的方式
- 27io stream, byte output stream, OutputStream writes data to file
- Hongliao Technology: Liu qiangdong's "heavy hand"
- C language learning notes (mind map)
猜你喜欢

RustDesk 搭建一个自己的远程桌面中继服务器

Station B, Master Liu Er - back propagation

Game push image / table /cv/nlp, multi-threaded start

B站刘二大人-反向传播

应用安全系列之三十七:日志注入

Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028

Memory and stack related concepts
![[Jiudu OJ 08] simple search x](/img/a7/12a00c5d1db2deb064ff5f2e83dc58.jpg)
[Jiudu OJ 08] simple search x

Station B Liu Erden linear regression pytoch

实践分享:如何安全快速地从 Centos迁移到openEuler
随机推荐
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
c语言——冒泡排序
LTE CSFB process
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
Station B Liu Erden softmx classifier and MNIST implementation -structure 9
Embedded interview questions (IV. common algorithms)
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
Database: ODBC remote access SQL Server2008 in oracel
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
Text classification still stays at Bert? The dual contrast learning framework is too strong
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
Web Security (VI) the use of session and the difference between session and cookie
Auto. JS learning notes 17: basic listening events and UI simple click event operations
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
Embedded interview questions (I: process and thread)
Rustdesk builds its own remote desktop relay server
Clear floating mode
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
Quantitative description of ANC noise reduction
P2802 go home