USACO 2.3.2 Cow Pedigrees (DP)

USACO 2.3.2 Cow Pedigrees (DP)

/**/ /*
ID: lorelei3
TASK: nocows
LANG: C++
*/


#include 
< fstream >

using   namespace  std;

const   int  K  =   105 ;
const   int  N  =   205 ;
const   int  MOD  =   9901 ;

int  dp[K][N];
int  s[K][N];

int  k,n;

int  main() {

    
int i,j,m,c;

    ifstream 
in("nocows.in");
    ofstream 
out("nocows.out");

    
in>>n>>k;

    dp[
1][1]=1;

    
for(i=2; i<=k; ++i){
        
for(j=1; j<=n; j+=2)
            
for(m=1; m<=j-1-m; m+=2){
                
if(m==j-1-m)    c=1;
                
else    c=2;

                dp[i][j] 
+= c* ( dp[i-1][m]*s[i-2][j-1-m] +
                                dp[i
-1][j-1-m]*s[i-2][m] +
                                dp[i
-1][m]*dp[i-1][j-1-m] );
                dp[i][j] 
%= MOD;
            }

    
        
for(j=0; j<=n; ++j){
            s[i
-1][j] += dp[i-1][j] + s[i-2][j];
            s[i
-1][j] %= MOD;
        }

    }


    
out<<dp[k][n]<<endl;
    
return 0;
}

你可能感兴趣的:(USACO 2.3.2 Cow Pedigrees (DP))