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: >>12 2010-10-21 12:30

Fuck, my brain is dead today. Final version:

Start with two indices, i and j, and an integer N representing the sum of all numbers between A[i] and a[j], inclusively, all initialized to zero.
1) Add A[j] to N, increment j.
2) If N = x, you're done. If N < x, back to the step 1.
3) Subtract A[i] from N. Increment i. Go to step 2.

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