版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons)
Problem F: 走道铺砖[减弱版]
Description
有一个m行n列的矩阵,用1*2的骨牌(可横放或竖放)完全覆盖,骨牌不能重叠,有多少种不同的覆盖的方法?你只
需要求出覆盖方法总数的值即可。
Input
三个整数数n,m
n<=10
Output
一个整数:总数
Sample Input
7 2
Sample Output
21
HINT
#include<bits/stdc++.h>
using namespace std;
int a,b,ans=0;
bool mp[100][100];
void dfs(int x,int y){
if(x==a+1){
ans++;
return;
}
if(mp[x][y]==false){
if(y==b)dfs(x+1,1);
else dfs(x,y+1);
}
if(mp[x][y]==true){
if(y<b){
if(mp[x][y+1]==true){
mp[x][y]=0;
mp[x][y+1]=0;
if(y+1==b)dfs(x+1,1);
else dfs(x,y+1);
mp[x][y+1]=1;
mp[x][y]=1;
}
}
if(x<a){
if(mp[x+1][y]==true){
mp[x+1][y]=false;
mp[x][y]=false;
if(y==b)dfs(x+1,1);
else dfs(x,y+1);
mp[x+1][y]=true;
mp[x][y]=true;
}
}
}
}
int main(){
cin>>a>>b;
memset(mp,1,sizeof(mp));
dfs(1,1);
cout<<ans;
return 0;
}