用1×2骨牌覆盖n×m棋盘,有多少种方法

传送门1:UVA 11270 Tiling Dominoes

#include<bits/stdc++.h>
using namespace std;
const int maxn=1<<12;
long long dp[2][maxn];
int cur,n,m;

void add(int a,int b){
    if(b&(1<<m))
        dp[cur][b^(1<<m)]+=dp[cur^1][a];
}

int main(){
    while(scanf("%d%d",&n,&m)!=EOF){
        if(n<m)
            swap(n,m);
        int all=(1<<m)-1;
        memset(dp,0,sizeof(dp));
        dp[0][all]=1;
        cur=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){
                cur^=1,memset(dp[cur],0,sizeof(dp[cur]));
                for(int sta=0;sta<=all;sta++){
                    if(dp[cur^1][sta]==0)
                        continue;
                    add(sta,sta<<1);//这个点不放,sta<<1让sta的最后一位为0
                    if(i && !(sta & ( 1<<(m-1) ) ) )//竖着放,不是第一行,而且上面的位置没放
                        add(sta,(sta<<1)^(1<<m)^1);
                    if(j && !(sta & 1) )    //横着放
                        add(sta,(sta<<1)^3);
                }
            }
        printf("%lld\n",dp[cur][all]);
    }
    return 0;
}

传送门2:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1971

#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int t,n,m;
    while(~scanf("%d%d",&n,&m))
    {
        if(n>1&&m>1&&(m*n%8==0))  puts("YES");
        else puts("NO");
    }
    return 0;
}

传送门3: https://vijos.org/p/1194

#include<bits/stdc++.h>// https://vijos.org/p/1194
using namespace std;
const int N=55;
const int ag[]={0,3,6,12,15,24,27,30};
typedef long long ll;
struct node
{
    ll f[N][N];
    void init()
    {
        memset(f,0,sizeof f);
        for(int i=0;i<N;i++) f[i][i]=1;
    }
};//ans=ans*pw(a,n);  ans和a 都是自己构造的 
int p,h;//记得给h赋值
node operator *(node x,node y)
{
    node res;
    memset(res.f,0,sizeof res.f);
    for(int i=0;i<h;i++)
    for(int j=0;j<h;j++)
    for(int k=0;k<h;k++)
        res.f[i][j]=(res.f[i][j]+x.f[i][k]*y.f[k][j])%p;
    return res;
}
node pw(node x,int y)
{
    node res;
    res.init();
    while(y)
    {
        if(y&1) res=res*x;
        y>>=1;
        x=x*x;
    }
    return res;
}
int main()
{
    int n,m;
    scanf("%d%d%d",&n,&m,&p);
    node ans;
    h=1<<m;
    for(int i=0;i<h;i++)
    for(int j=0;j<h;j++)
    if( ((~i)&j)==((~i)&(h-1)) )
    {
        int tmp=0;
        for(int k=0;k<=8;k++)
            tmp=tmp||( (i&j)==ag[k] );
        ans.f[i][j]=tmp;
    }
    ans=pw(ans,n);
    printf("%d\n",ans.f[h-1][h-1]);
}
传送门4:http://acm.nyist.net/JudgeOnline/problem.php?pid=1273

http://blog.csdn.net/f_zyj/article/details/56037695

#include<bits/stdc++.h>// https://vijos.org/p/1194
using namespace std;
const int N=55;
const int ag[]={0,3,6,12,15,24,27,30};
struct node
{
    int f[N][N];
    void init()
    {
        memset(f,0,sizeof f);
        for(int i=0;i<N;i++) f[i][i]=1;
    }
};//ans=ans*pw(a,n);  ans和a 都是自己构造的
int p=997,h=16;//记得给h赋值
node operator *(node x,node y)
{
    node res;
    memset(res.f,0,sizeof res.f);
    for(int i=0;i<h;i++)
    for(int j=0;j<h;j++)
    for(int k=0;k<h;k++)
        res.f[i][j]=(res.f[i][j]+x.f[i][k]*y.f[k][j])%p;
    return res;
}
node pw(node x,int y)
{
    node res;
    res.init();
    while(y)
    {
        if(y&1) res=res*x;
        y>>=1;
        x=x*x;
    }
    return res;
}
int solve(int n)
{
    node ans;
    memset(ans.f,0,sizeof ans.f);
    for(int i=0;i<h;i++)
    for(int j=0;j<h;j++)
    if( ((~i)&j)==((~i)&(h-1)) )
    {
        int tmp=0;
        for(int k=0;k<=8;k++)
            tmp=tmp||( (i&j)==ag[k] );
        ans.f[i][j]=tmp;
    }
    ans=pw(ans,n);
    return ans.f[h-1][h-1]%p;
}
int main()
{
    int n,m,k,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        printf("%d %d\n",solve(m-1),solve(n-m-k+1));
    }
    return 0;
}


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值