Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions p2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Problem

Exercises 15.3‐5<br>
Suppose that in the rod-cutting problem, we also had limit l<sub>i</sub> on the number of pieces of length i that we are allowed to produce, for i = 1, 2, ..., n. Show that the **optimal-substructure** property described in Section 15.1 (unit05-演算法.pdf p28) no longer holds.

# Solution

## Example

| length i | 1 | 2 | 3 | 4 | 5 |
|:------:|:-:|:-:|:-:|:-:|:-:|
| price p<sub>i</sub> | 10 | 15 | 24 | 28 | 35 |
| limit l<sub>i</sub> | 3 | 1 | 1 | 1 | 1 |

長度為 5 的 rod 可切為

- [5] 35元
- [1, 4] 34元
- [2, 3] 39元
- [1, 1, 3] 44元
- [1, 2, 2] 違反limit
- [1, 1, 1, 2] 45元
- [1, 1, 1, 1, 1] 違反limit

## Analysis

i = 5 時,最佳解為 [1, 1, 1, 2] 45元。當我們再看 它的 sub-problem i = 2 的時候,解法有 [1, 1] 20元、[2] 15元,最佳解為 [1, 1],**但是**我們卻不能將之套用回 i = 5的原問題,因為它違反了長度為 1 的 rod 數目限制 (l<sub>1</sub> = 3)。