Tiling Dominoes
Time Limit: 1000MS 64bit IO Format: %lld & %llu
最基础的插头dp轮廓线dp
但是刘汝佳讲的并不能懂。。一堆函数乱入。
既然不能简单的用行列为状态来表示,那么把轮廓线也加到状态里面。
把每个格子看成一个阶段,每个阶段里面有2^m个状态,对应这个格子前面m个格子的状态(因为只有前面m个格子能影响当前格子的决策),那么分成当前格子留白,往上放,往左放三种决策,格子对应一些限制条件,留白需要上一行同一列的格子为1;往左同样需要上一行的为1,并且还要前面一个格子为0;往上需要上面的格子为0.
那么dp方程其实很好写的不要被刘汝佳迷惑了。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<ctime>
#include<climits>
#include<cctype>
#include<algorithm>
#ifdef WIN32
#define AUTO "%I64d"
#else
#define AUTO "%lld"
#endif
using namespace std;
#define smax(x,tmp) x=max((x),(tmp))
#define smin(x,tmp) x=min((x),(tmp))
#define maxx(x1,x2,x3) max(max(x1,x2),x3)
#define minn(x1,x2,x3) min(min(x1,x2),x3)
typedef long long LL;
const int maxn = 105;
const int maxm = 1<<11;
LL dp[maxn][maxm];
int n,m;
inline bool init()
{
if(!~scanf("%d%d",&n,&m)) return false;
if(m>n) swap(m,n);
return true;
}
LL dynamic()
{
memset(dp,0,sizeof(dp));
dp[0][(1<<m)-1]=1ll; // set the 0 node to be uncoverable
int cur=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cur++;
for(int k=0;k<(1<<m);k++)
{
if(k & (1<<m-1)) dp[cur][(k<<1)^(1<<m)] += dp[cur-1][k];
if(i^1 && !(k&(1<<m-1))) dp[cur][(k<<1)^1] += dp[cur-1][k];
if(j^1 && !(k&1) && (1<<m-1)) dp[cur][(k<<1)^(1<<m)^3] += dp[cur-1][k];
}
}
return dp[m*n][(1<<m)-1];
}
int main()
{
freopen("domino.in","r",stdin);
freopen("domino.out","w",stdout);
while(init())
{
LL ans = dynamic();
printf(AUTO "\n",ans);
}
return 0;
}