how to solve SSHUFLE on spoj

i coded this question using 3-D dp approach but get weird ans for sample test cases.
please help.
problem link:link text
code link:link text

Here is the recursion part of my accepted 3-D memorization DP solution:

long long solve(int i, int j, int k, string a, string b, string c) { if (k == c.size()) return 1; long long ans = 0; for (int x = i; x < a.size(); x++) if (a[x] == c[k]) ans += solve(x+1, j, k+1, a, b, c); for (int x = j; x < b.size(); x++) if (b[x] == c[k]) ans += solve(i, x+1, k+1, a, b, c); return ans; }

You can memorize the recursion using a 3-D array like dp[65][65][65]; since the maximum size of strings a, b and c is 60.

thanks man, i got my mistake.