-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0191f68
commit 95fb735
Showing
9 changed files
with
3 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
# 背包问题 | ||
|
||
# 0-1 背包 | ||
|
||
01 背包的状态转换方程 `f[i,j] = Max{ f[i-1,j-Wi]+Pi( j >= Wi ), f[i-1,j] }` | ||
|
||
(1) V(i,0)=V(0,j)=0 (2) V(i,j)=V(i-1,j) j<wi\ | ||
V(i,j)=max{V(i-1,j) ,V(i-1,j-wi)+vi) } j>wi (1) 式表明:如果第 i 个物品的重量大于背包的容量,则装人前 i 个物品得到的最大价值和装入前 i-1 个物品得到的最大价是相同的,即物品 i 不能装入 背包;第 (2) 个式子表明 : 如果第 i 个物品的重量小于背包的容量,则会有一下两种情况:(a) 如果把第 i 个物品装入背包,则背包物品的价值等于第 i-1 个 物品装入容量位 j-wi 的背包中的价值加上第 i 个物品的价值 vi; (b) 如果第 i 个物品没有装入背包,则背包中物品价值就等于把前 i-1 个物品装入容量为 j 的背包中所取得的价值。显然,取二者中价值最大的作为把前 i 个物品装入容量为 j 的背包中的最优解。 | ||
|
||
有编号分别为 a,b,c,d,e 的五件物品,它们的重量分别是 2,2,6,5,4,它们的价值分别是 6,3,5,4,6,现在给你个承重为 10 的背包,如何让背包里装入的物品具有最大的价值总和? | name | weight | value | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | | ---- | ------ | ----- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | | a | 2 | 6 | 0 | 6 | 6 | 9 | 9 | 12 | 12 | 15 | 15 | 15 | | b | 2 | 3 | 0 | 3 | 3 | 6 | 6 | 9 | 9 | 9 | 10 | 11 | | c | 6 | 5 | 0 | 0 | 0 | 6 | 6 | 6 | 6 | 6 | 10 | 11 | | d | 5 | 4 | 0 | 0 | 0 | 6 | 6 | 6 | 6 | 6 | 10 | 10 | | e | 4 | 6 | 0 | 0 | 0 | 6 | 6 | 6 | 6 | 6 | 6 | 6 | | ||
|
||
![](http://images.cnitblog.com/blog/454792/201303/23110036-37762cbba6484ef3a7e3570062b099c9.png) | ||
|
||
f[i,j]表示在前 i 件物品中选择若干件放在承重为 j 的背包中,可以取得的最大价值。 Pi 表示第 i 件物品的价值。决策:为了背包中物品总价值最大化,第 i 件物品应该放入背包中吗 ? |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.