Difference between revisions of "TADM2E 3.12"
From Algorithm Wiki
(Recovering wiki) |
Manish.khkr (talk | contribs) m |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | Let's put into the black box whole set <math>S=\{x_i\}_{i=1}^n</math>. If <math>bb(S)</math> is True, then such subset | + | Let's put into the black box whole set <math>S=\{x_i\}_{i=1}^n</math>. If <math>bb(S)</math> is True, then such a subset exists and we can go on: |
# R:=S | # R:=S | ||
# for i:=1 to n do | # for i:=1 to n do | ||
## If <math>bb(R/\{x_i\})</math> is True then <math>R:=R/\{x_i\}</math> | ## If <math>bb(R/\{x_i\})</math> is True then <math>R:=R/\{x_i\}</math> | ||
When this iteration is finished R will be subset of S that adds up to k. | When this iteration is finished R will be subset of S that adds up to k. | ||
+ | |||
+ | Above solution works even when there are multiple subsets that add up to k. |
Latest revision as of 08:59, 26 December 2019
Let's put into the black box whole set $ S=\{x_i\}_{i=1}^n $. If $ bb(S) $ is True, then such a subset exists and we can go on:
- R:=S
- for i:=1 to n do
- If $ bb(R/\{x_i\}) $ is True then $ R:=R/\{x_i\} $
When this iteration is finished R will be subset of S that adds up to k.
Above solution works even when there are multiple subsets that add up to k.