题解
2023-05-07 17:59:13
发布于:上海
72阅读
0回复
0点赞
#include <iostream>
using namespace std;
int a[10][10];
int n,m,x,y,count=0;
int fd[2][8]={
{-2,-2,-1,-1,1,1,2,2},
{1,-1,2,-2,2,-2,1,-1}
};
int step=0;
void dfs(int h,int l){
if(step==n*m){
count++;
}else{
//zou
for(int i=0;i<8;i++){
int nh,nl;
nh = h+fd[0][i];
nl = l+fd[1][i];
if(a[nh][nl]==0&&nh>=0&&nh<n&&nl>=0&&nl<m){
a[nh][nl]=1;
step++;
dfs(nh,nl);
a[nh][nl] = 0;
step--;
}
}
}
}
int main(){
int t;
cin >> t;
for(int i=0;i<t;i++){
cin >> n >> m >> x >> y;
a[x][y] = 1;
step++;
dfs(x,y);
}
cout << count;
return 0;
}
全部评论 1
主函数要加这一段
for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ a[i][j]=0; } }
2024-07-02 来自 吉林
0
有帮助,赞一个