#include<stdio.h>
#include<string.h>
#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
long long dp[33][1<<4];
int map[1<<4][1<<4];
int n,m;
void dfs(int x,int y,int dep){
if(dep==m){
map[x][y]=1;
return;
}
int t1=(x>>dep)&1;
if(dep==m-1){
if(t1) dfs(x,y,dep+1);
else dfs(x,y+(1<<dep),dep+1);
return ;
}
int t2=(x>>(dep+1))&1;
if((!t1)&&(!t2)){
dfs(x,y,dep+2);
dfs(x,y+(1<<dep),dep+1);
}
if((!t1) && t2){
dfs(x,y+(1<<dep),dep+2);
}
if(t1){
dfs(x,y,dep+1);
}
}
long long deal(){
if(m==0) return 1;
if(n*m %2) return 0;
memset(map,0,sizeof(map));
for(int x=0;x<(1<<m);x++)
dfs(x,0,0);
memset(dp,0,sizeof(dp));
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int x=0;x<(1<<m);x++) if(dp[i-1][x])
for(int y=0;y<(1<<m);y++){
if(map[x][y]) dp[i][y]+=dp[i-1][x];
}
}
return dp[n][0];
}
int main()
{
// freopen("in.in","r",stdin);
while(~scanf("%d",&n)&&(n!=-1)){
m=min(n,3);
n=max(n,3);
cout<< deal() << endl;
}
return 0;
}
poj 2663 压缩DP
最新推荐文章于 2019-04-19 16:54:00 发布