Poj Solution 3934

http://poj.org/problem?id=3934

#include <stdio.h>
int dp[81][201];
int main()
{
    int n,m,i,j,k;
    for(i=1;i<=80;i++){
        for(j=0,k=i-1;j<k;j++) dp[i][j]=0;
    }
    dp[1][0]=1;
    dp[2][1]=2;
    dp[3][2]=4;
    dp[3][3]=2;
    for(i=4;i<=80;i++){
        for(j=i-1;j<=200;j++){
            dp[i][j]=0;
            if(j>=2) dp[i][j]=(dp[i-1][j-2]*(i-2))%9937;
            if(j>=1) dp[i][j]=(dp[i][j]+dp[i-1][j-1]*2)%9937;
        }
    }
    while(scanf("%d%d",&n,&m),n||m){
        if(m>=200) printf("0n");
        else printf("%dn",dp[n][m]);
    }
    return 0;
}
 


											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *