UVA 11270 Tiling Dominoes [插头dp]

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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值