1219:马走日

#include<bits/stdc++.h>
using namespace std;
int vis[8][2]={-2,1,-1,2,1,2,2,1,2,-1,1,-2,-1,-2,-2,-1};//构造偏移量数组
int t,n,m,x,y,ans;//棋盘总共由(n)(m)个点 
bool st[100][100];//如果st[i][j]==0 表示i,j这个坐标没有走过 st[a][b]==1表示a,b这个坐标走过 

void dfs(int x,int y,int cnt){
	//出口 所有的点全部访问了
	if(cnt==(n)*(m)) {
		ans++;//按题操作 
		return;
	}
	//深搜就是暴力枚举
	for(int i=0;i<8;i++){
		int tx=x+vis[i][0],ty=y+vis[i][1];
		//判断是否合法:有没有越界、有没有走过
		if(tx>=0&&tx<n&&ty>=0&&ty<m && st[tx][ty]==0){
			//保存现场
			st[tx][ty]=1;
			dfs(tx,ty,cnt+1);
			//还原现场 
			st[tx][ty]=0; 
		} 
	} 
	return;
} 

int main()
{
    cin>>t;
    while(t--){
    	cin>>n>>m>>x>>y;
    	//多组数据---》清空上轮数据对本轮的影响 
    	memset(st,0,sizeof(st));
    	ans=0;
    	st[x][y]=1;
    	dfs(x,y,1);
    	cout<<ans<<endl;
	}
	return 0;
}

相关推荐

  1. 1213

    2024-07-18 20:48:05       67 阅读
  2. Python【出棋盘】

    2024-07-18 20:48:05       47 阅读
  3. CCF-迷宫(bfs)

    2024-07-18 20:48:05       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 20:48:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 20:48:05       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 20:48:05       58 阅读
  4. Python语言-面向对象

    2024-07-18 20:48:05       69 阅读

热门阅读

  1. 数据结构第28节 字典树

    2024-07-18 20:48:05       20 阅读
  2. 详解深度学习中的epochs

    2024-07-18 20:48:05       23 阅读
  3. 梧桐数据库: 数据库技术中的重写子查询技术

    2024-07-18 20:48:05       22 阅读
  4. ubuntu 可以直接在图像界面打开命令行吗

    2024-07-18 20:48:05       18 阅读
  5. pandas库学习之read_excel函数

    2024-07-18 20:48:05       16 阅读