求助!
查看原帖
求助!
781798
Zhanghaoxiang930楼主2024/7/16 19:35
#include<bits/stdc++.h>
#define ll long long
#define maxn 150000
using namespace std;
const int N = 100000 + 5;
int t,n,m,xa,ya,xb,yb,xc,yc,sum;
int ax[5]={0,-1,1,0,0},ay[5]={0,0,0,-1,1}; 
bool b[200][200];
bool check(int x,int y,int t){
	if(!b[x][y]||x<=0||x>n+1||y<=0||y>m+1) return false;
	if(t==floor(n*m/4)&&(x!=xa||y!=ya)) return false;
	if(t==floor(n*m/2)&&(x!=xb||y!=yb)) return false;
	if(t==floor(n*m*3/4)&&(x!=xc||y!=yc)) return false;
	return true;
}void dfs(int x,int y,int t){
	if(x==1&&y==2&&t==n*m) sum++;
	for(int i=1;i<=4;i++){
		int nx=x+ax[i],ny=y+ay[i];
		if(check(nx,ny,t+1)){
			b[nx][ny]=false;
			dfs(nx,ny,t+1);
			b[nx][ny]=true;
		}
	}return ;
}
int main(){
	cin>>t;
	while(t--){
		memset(b,true,sizeof(b));
		cin>>n>>m;
		cin>>xa>>ya>>xb>>yb>>xc>>yc;
		xa++,ya++,xb++,yb++,xc++,yc++;
		sum=0;
		dfs(1,1,0);
		cout<<sum<<endl;
	}
}

输出全输出0

2024/7/16 19:35
加载中...