forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
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
619c5c2
commit b638ea9
Showing
1 changed file
with
9 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...ogramming/1449.Form-Largest-Integer-With-Digits-That-Add-up-to-Target/Readme.md
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### 1449.Form-Largest-Integer-With-Digits-That-Add-up-to-Target | ||
|
||
这是一道有点类似无限背包的DP问题。 | ||
|
||
令dp[cap]表示使用总分为cap所能得到的最优解(即最大的数字的字符串形式)。突破口是考察最后一个数字i是什么。我们遍历i的可能性:只要cap>=cost[i],那么dp[cap]就可以由dp[cap-cost[i]]追加数字i转化而来。我们在所有的i中,找一个能使dp[cap]最大的解。注意,这里的“最大解”,在字符串意义而言,首先是越长越好,其次是相同长度下字典序越大越好。 | ||
|
||
注意体会这和01背包问题解法的不同。01背包问题的外循环是遍历物品,内循坏是遍历容量。每考虑一件物品,更新所有的dp[cap]。 | ||
|
||
相反,无限背包问题的外循环是遍历容量,内循环是遍历(最后一次使用的)物品。每考虑一个容量cap,搜索最有的dp[cap]. |