I am trying to resolve subsets from the USACO training gateway ...
Problem Statement
For many sets of consecutive integers from 1 to N (1 <= N <= 39), this set can be divided into two sets whose sums are identical.
For example, if N = 3, you can partition the set {1, 2, 3} so that the sums of both subsets are the same:
{3} and {1,2} This is considered the only division (that is, it cancels the number of orders as the same split and, therefore, does not increase the number of splits).
If N = 7, there are four ways to split the set {1, 2, 3, ... 7} so that each section has the same amount:
{1,6,7} and {2,3,4,5} {2,5,7} and {1,3,4,6} {3,4,7} and {1,2,5,6 } {1,2,4,7} and {3,5,6} Given N, your program should print the number of ways in which a set containing integers from 1 to N can be divided into two sets whose sums are identical . Print 0 if no such paths exist.
Your program should calculate the answer, and not look for it from the table.
End
Before I worked on O (N * 2 ^ N), simply rearranging through the set and finding the sums.
Finding out how terribly inefficient I went on to display the sequences of sums ... http://en.wikipedia.org/wiki/Composition_(number_theory )
After many coding problems, to clear the repetitions is still too slow, so I went back to the square: (.
Now, when I look at the problem more closely, it seems that I should try to find a way not to find the sums, but actually go directly to the number of sums using some kind of formula.
If anyone can give me directions on how to solve this problem, I am all ears. I am programming in java, C ++ and python.