Tri Tiling [POJ 2663]

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

View Code
//放骨牌类问题,dfs枚举方法,递推。 
const int MM = 1111;
#define debug puts("wrong")
typedef __int64 int64;
int64 N,M,dp[111][11];

void dfs(int64 row,int64 col,int64 pre,int64 now,int64 ss) {
    if(col>=3) {
        if(pre==7) dp[row][now]+=ss;
        return;
    }
    if((pre&(1<<col))!=0) dfs(row,col+1,pre,now,ss);
    else {
        dfs(row,col+1,pre|(1<<col),now|(1<<col),ss);
        if(col<2 && (pre&(1<<(col+1)))==0) {
            int64 tmp=(1<<col)|(1<<(col+1));
            dfs(row,col+2,pre|tmp,now,ss);
        }
    }
}
void solve() {
    int64 i,j,k,state=(1<<3)-1;
    memset(dp,0,sizeof(dp)); dp[0][state]=1;
    for(i=1;i<=(N+1);i++) {
        for(j=0;j<=state;j++) {
            if(dp[i-1][j]==0) continue;
            dfs(i,0,j,0,dp[i-1][j]);
        }
    }
    printf("%I64d\n",dp[N+1][0]);
}

int main() {
    while(scanf("%I64d",&N),N!=-1)  solve();    
    return 0;
}

 

posted @ 2013-05-03 21:41  zhang1107  阅读(211)  评论(0编辑  收藏  举报