当前位置:网站首页>Dynamic programming | 0-1 knapsack problem
Dynamic programming | 0-1 knapsack problem
2022-07-18 05:04:00 【@Misty rain fell on the city】
1、 Problem analysis
Yes n The capacity of items and shopping carts , Each item weighs w[i], Value is v[i], The capacity of the shopping cart is W. Select several items and put them in the shopping cart , Maximize its value , It can be expressed as follows :

The problem boils down to solving the constraint conditions , The solution vector that maximizes the objective function X = {x1,x2,…,xn}.
First, we analyze whether the problem has optimal substructure properties .
(1) Analyze the structural characteristics of the optimal solution
- Suppose until X = {x1,x2,…,xn} It's the original question {a1,a2,…,an} The best solution , Then the original problem becomes a sub problem after removing the first item {a2,a3…,an}, Pictured 4-89 Shown .

- The constraints and objective functions of the subproblem are as follows .

- We just need to prove : X’ = {x2,x3,…,xn} It's the original question {a2,a3,…,an} The best solution , That is, the optimal substructure property is proved .
(2) Establish the recursive formula of the optimal value
use c[i][j] Before presentation i Put one item into a container with a capacity of j The maximum value you can get from your shopping cart .
- Don't put it in the second i Item ,xi = 0
边栏推荐
猜你喜欢

sentinel1.8.4 持久化nacos配置

H5 cloud image background reading and writing CAD files - Online CAD, web CAD, web browsing and editing CAD

争议中的换电:头部玩家的有限游戏

Generate XML file of VOC dataset

云中断的三个主要原因

普歌-码上鸿鹄团队-Vscode 代码格式化整理

uni-app打电话功能

清晰的理解大端和小端

Motion capture assists China Electric Power Research Institute in establishing a side cloud collaborative power independent inspection system

Sqli labs less-1 (updatexml of error injection)
随机推荐
Huawei cloud stack opens its framework to the south to help ecological partners enter the cloud efficiently
uni-app做微信登录(待写完)
EN 1317-5道路约束系统产品—CE认证
Trees and binary trees
栈的应用—
SN6 multispectral and SAR data fusion
Docker---Docker安装,Docker上MySQl安装,并将项目部署在Docker上
ASTM E595-15(2021) Outgassing除气测试最新标准
Niuke 2021 summer training 8-f-robots
电商平台后台管理系统--->操作方法说明
hbuilder提交代码
华为云Stack南向开放框架,帮助生态伙伴高效入云
普歌—码上鸿鹄团队 winSCP和Xshell 基本配置用法
Sqli labs less-1 (updatexml of error injection)
1、 MySQL Foundation
云中断的三个主要原因
信息系统项目管理师核心考点(十一)物联网两项关键技术和架构
创建线程的方式
LeNet
C#文件和文件夹输入输出流代码