Sum of Subset Problem: Dynamic Programming Approach
A set of positive integers S = {3, 9, 2, 6, 5} is given. The task is to determine if there exists a subset of S that sums exactly to m = 10. To solve this problem, we will use the dynamic programming approach discussed in class.
The table below shows the step-by-step calculation using the dynamic programming approach:
| | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|----|
| S | 0 | {} | 3 | | | | | | | | |
| 2 | 9 | 3 | | | | | | | | | |
| 4 | 6 | 5 | 5 | | | | | | | | |
To find the subset that sums exactly to 10, we backtrack from the rightmost corner of the table. The result is as follows:
Subset: {2, 3, 5}