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-21 12:13

>>1
Listen carefully, because I'm not going to say post this twice.
For a n-length sequence of 1's and 2's, create an nxn matrix called m. Define m[x][y] to be the sum of all elements of your input array from A[x] to A[x+y-1], inclusively. Filling this matrix efficiently without recomputing the entire sum is left as an exercise to the reader (now you have two exercises). Please note that entries past x+y>n will be undefined. Now that you've formed your matrix, just search for x in it. The row and column at which you will find it will indicate your solution.

You're welcome, faggot.

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