{ -3, -4, 3, 4 } -> { -3, -4, 3, 4 } { -5, -4, -3, 3, 4 } -> { -5, -4, 3, 4 }, {-3 } { -5, -4, -4, -1 } -> { -5, -4, -4, -1 } { -5, -4, -4, -1, -1, -1 } -> { -5, -4, -4, -1 }, { -1, -1 } { -3, 1, 1, 1, 1, 4, 6 } -> { -3 }, { 4, 6 }, { 1 }, { 1 }, { 1 }, { 1 } { -3, 0, 1, 1, 1, 4, 6 } -> { -3 }, { 4, 6 }, { 1 }, { 1 }, { 1 }, { 1 } { -3, 0, 1, 1, 1, 4, 6 } -> { -3, 0 }, { 4, 6 }, { 1 }, { 1 }, { 1 } { -3, -2, 0, 1, 1, 4, 6 } -> { -3, -2 }, { 4, 6 }, { 1 }, { 1 }, { 0 }So, that's your first job -- to figure out the partitions.
Once you've done that, you now need to make some large calculations. What I did was write some procedures to handle really large numbers, which I represented as deque's of digits. Here were my procedures:
/* Multiply arbitrarily long positive number s, with a single digit number n, and change s to reflect the resuilt */ void mult(deque <int> &s, int n); /* Add two arbitrarily large positive numbers s1 and s2, and put the result into s1 */ void add(deque <int> &s1, deque <int> &s2); /* Subtract the number s from arbitrarily large number s1, and modify s1 to hold the result. All numbers are positive, and s1 is greater than s2. */ void sub(deque <int> &s1, int s2) /* Multiply arbitrarily long positive number s, with a positive integer n. This calls mult() to do the single digit multiplications */ void longmult(deque <int> &s, int n) |
This is a problem where the problem itself and the individual components are all really straightforward. You just need to get everything ordered correctly.