I can't implement the State-space tree. How to implement it for subset sum problem?
What's the complexity of this?
Thanks in advance.
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | nor | 157 |
6 | maroonrk | 155 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
8 | orz | 146 |
10 | BledDest | 145 |
I can't implement the State-space tree. How to implement it for subset sum problem?
What's the complexity of this?
Thanks in advance.
Name |
---|
Could you explain a little bit more on what you're trying to ask? Sorry if I'm sounding a bit rough
I have a set of positive integers. I have to tell if there any subset of S that all elements summation equal to given sum. I have done it with DP with O(sum*n) complexity. But here sum can be 10^9. So what's will be the approach?
n>=30 and sum>=10^9
Knapsack problem with large weights can be done in O(2^n), but there is another algo. You can divide array into left and right parts. For the first part calc array f of all possible sums (i used bitmasks). For the second make map m, m[x] = 1 if it is possible to make sum x in the second part. Now go through array f and if m[sum — f[i]] == 1 answer is yes.