DP と Greedy の両方が最適部分構造を必要とします。違いは:Greedy には貪欲選択性(局所最適解が大域最適解である)も必要ですが、DP は複数の選択肢と重複する部分問題を検討する必要がある場合に必要です。
なぜ重要なのか
text
Optimal substructure? -- both need this
+ greedy-choice property holds? -> GREEDY (fast, one pass of choices)
+ must compare many sub-solutions / they overlap? -> DYNAMIC PROGRAMMING
古典的な対比:コイン両替
python
():
INF = ()
dp = [] + [INF] * amount
a (, amount + ):
c coins:
c <= a:
dp[a] = (dp[a], dp[a - c] + )
dp[amount]
min_coins(, [, , ])
