Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Algorithm

Name: Anonymous 2010-10-21 11:53

There's a n-element array of integers- 1 or 2.
We have to find subsequence which sum equals x.
How to do that ? I have no fucking idea.
Inb4 bruteforce

Name: Anonymous 2010-10-22 4:07

>>36
Wow you are stupid. He clearly said he wanted one solution ("We have to find subsequence", not "We have to find all subsequences"). Subsequence is the same thing as substring. If you're thinking about subsets, then the problem becomes just [i]trivial[i]. If you just need to find one subset with sum of X, you just pick up to X/2 integers with value of 2 from array, then enough ones for sum to reach X if necessary. This is O(n) in worst case.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List