If this problem should be solvable; then sum(ALL)/3 must be an integer. Any solution should have SUM(J) + SUM(K) = SUM(I) + sum(ALL)/3 . This is a solution to the 2-partition problem over concat(ALL, {sum(ALL)/3}) .
You say that you have an implementation with two sections: use it to solve this problem. Then (at least) one of the two sections will contain the number sum(ALL)/3 - remove the number from this partion, and you find I For another partition, run the 2 partition again to share J with K ; after all, J and K must be equal on their own.
Edit: This solution is probably incorrect - a 2-bit concatenated set will have several solutions (at least one for each of I, J, K), however, if there are other solutions, then the "other side" may not consist of a union two of I, J, K and generally cannot be splittable. You will need to think, I'm afraid :-).
Try 2: Iterating over a multiset, keeping the following map: R(i,j,k) :: Boolean , which represents the fact that prior to the current iteration, numbers allow division into three multisets that have sums I , J , K Ie For any R(i,j,k) and the next number n in the next state R' it contains R'(i+n,j,k) and R'(i,j+n,k) and R'(i,j,k+n) . Note that the complexity (in accordance with the examination) depends on the value of the input numbers; it is a pseudopolynomial time algorithm. Nikita's solution is conceptually similar, but more efficient than this, because it does not track the third set amount: it is unnecessary, because you can trivially calculate it.
Eamon nerbonne
source share