here is my code:

[cpp]

#include <stdio.h>

long long ways[400][200];

long long sum[400][200];

long long getways( int n, int d );

long long anyN( int k, int f ){

long long m=0;

if ( k<0 || f<0 ) return 0;

if ( sum[k][f] != -1 ) return sum[k][f];

// for ( int i=0; i<=f; i++ ) m+=getways(k,i);

return (sum[k][f]=getways(k,f)+anyN(k,f-1));

}

long long getways( int n, int d ){

if ( !n ) return !d;

if ( n<0 ) return 0;

if ( d<0 ) return 0;

if ( n%2 ) return 0;

if ( ways[n][d]!=-1 ) return ways[n][d];

long long m=0;

int i;

for ( i=2; i<n; i++ ){

m+=2*getways(i-2,d-1)*anyN( n-i,d-1 );

m+=getways(i-2,d-1)*getways(n-i,d);

}

m+=getways(n-2,d-1);

//printf( "subProb(%d,%d)=%lld\n", n,d,m );

return ways[n][d]=m;

}

int main( void ){

FILE *in=stdin;

int i,j,k,n,d;

while ( fscanf( in, "%d %d", &n, &d )==2 ){

for ( i=0; i<400; i++ ) for ( j=0; j<200; j++ ) sum

*[j]=ways*

*[j]=-1;*

printf( "%lld\n", getways( n,d ) );

}

return 0;

}

[/cpp]printf( "%lld\n", getways( n,d ) );

}

return 0;

}

[/cpp]