reuse allowed; prune when the sum overshoots
[2,2,2,2] r=-1
[2,2,2] r=1
[2,2,3] r=0
[2,2,6] r=-3
[2,2] r=3
[2,3,3] r=-1
[2,3] r=2
[2,6] r=-1
[2] r=5
[3,3,3] r=-2
[3,3] r=1
[3,6] r=-2
[3] r=4
[6,6] r=-5
[6] r=1
[7] r=0
ε r=7
combinations
(none yet)
Backtracking · non-decreasing picks with overshoot pruning
▸1combo(start, rem, path):2 if rem == 0: record path; return // exact hit3 for i in start..n−1:4 if cand[i] > rem: prune; continue // overshoot5 path.push(cand[i]) // choose6 combo(i, rem − cand[i], path) // explore (reuse: i, not i+1)7 path.pop() // un-choose8 return
state
- candidates[2, 3, 6, 7]
- target7