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:
Anonymous2010-10-22 3:19
How am I supposed to know the OP means when he doesn't explain it correctly? He doesn't know the difference between a subsequence and a substring and he never said whether he wanted one solution or all solutions.
>do you think every optimization problem can only be solved by exhaustive search too?
The problem is to find substrings that satisfy a certain condition. How the fuck are you supposed to do that without checking each one? You can return early if you find a solution, but that doesn't change the asymptotic running time. In the worst case there is no solution, which you can only determine by exhaustively searching all O(N^2) substrings and not finding an answer.