传送门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;
}