POJ 2411 Mondriaan's Dream 插头dp
题目链接:
http://poj.org/problem?id=2411
Mondriaan's Dream
Memory Limit: 65536K
题意
用
1*2
和2*1
的骨牌排满n*m
的方格。
题解
插头dp入门题
参考:port
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=13;
LL dp[2][1<<maxn];
int n,m;
int main() {
while(scf("%d%d",&n,&m)==2&&n){
if(n<m) swap(n,m);
int pre=0,cur=1;
clr(dp[cur],0);
dp[cur][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
swap(pre,cur);
clr(dp[cur],0);
int p1=(1<<j),p2=(1<<(j+1));
for(int k0=0;k0<(1<<(m+1));k0++){
int k=k0;
///注意!换行的时候的处理
if(!j) k=k0<<1;
if((p1&k)&&!(p2&k)){
dp[cur][k^p1]+=dp[pre][k0];
}else if(!(p1&k)&&(p2&k)){
dp[cur][k^p2]+=dp[pre][k0];
}else if(!(p1&k)&&!(p2&k)){
if(j<m-1) dp[cur][k^p2]+=dp[pre][k0];
if(i<n-1) dp[cur][k^p1]+=dp[pre][k0];
}
}
}
}
prf("%lld\n",dp[cur][0]);
}
return 0;
}
//end-----------------------------------------------------------------------