Can be solved in this way also :
> #include <iostream>
> #include <cstring>
>
> using namespace std;
>
> string a, b, c;
> int memo[51][51][51];
>
> int interleave(int ai, int bi, int ci)
> {
> int r1, r2;
>
> r1 = r2 = 0;
>
> if ( ai == a.size() && bi == b.size() && ci == c.size() ) {
> return 1;
> }
> if ( ci == c.size() )
> return 0;
> if ( ai == a.size() && bi == b.size() )
> return 0;
>
> if ( memo[ai][bi][ci] == -1 ) {
> if ( a[ai] != c[ci] && b[bi] != c[ci] )
> r1 = interleave (ai + 1, bi + 1, ci);
> if ( a[ai] == c[ci] )
> r1 = interleave (ai + 1, bi, ci + 1);
> if ( b[bi] == c[ci] )
> r2 = interleave (ai, bi + 1, ci + 1);
>
> return memo[ai][bi][ci] = r1|r2;
> }
>
> return memo[ai][bi][ci];
> }
>
> int main()
> {
> cin >> a >> b >> c;
>
> memset (memo, -1, sizeof(memo));
>
> cout << interleave(0, 0, 0) << endl;
>
> return 0;
> }
>
> On Fri, May 27, 2011 at 1:23 AM, sunny agrawal <[email protected]>wrote:
> two strings can be mixed up anywhere .. and yes the ordering of the
> characters in the original strings must be preserved while constructing the
> third string ??
>
> On Fri, May 27, 2011 at 1:04 PM, Senthil S <[email protected]> wrote:
>
>> @ sunny agrawal : I misinterpreted the question .. but im not clear about
>> how you define interleaving of two strings .. Should the two strings be
>> mixed up at constant intervals or they can be mixed up anywhere .. and
>> should the ordering of the characters in the original strings be preserved
>> while constructing the third string ??
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Sunny Aggrawal
> B-Tech IV year,CSI
> Indian Institute Of Technology,Roorkee
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
-Aakash Johari
(IIIT Allahabad)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.