有两个点TLE了,求调教
查看原帖
有两个点TLE了,求调教
867681
23_VS_24楼主2023/11/12 11:26
#include<bits/stdc++.h>
using namespace std;
int n,m;
int ans=0;
int a[31][31];
int xx[2]={1,0};
int yy[2]={0,1};//移动方向
void mag()//障碍
{   
	a[1][1]=1;
	for(int i=1;i<=30;i++){
		for(int j=1;j<=30;j++){
			if(i%2==0&&j%2==0){
				a[i][j]=2;
			}
		}
	}
	return ;
}
int ngm(int x,int y){
	if(x==n&&y==m){
		ans++;
	}
	for(int i=0;i<2;i++){
		int tx=x+xx[i];
		int ty=y+yy[i];//边界
		if(tx>n||ty>m||tx<1||ty<1||a[tx][ty]!=0) continue;
		a[tx][ty]=1;
		ngm(tx,ty);
		a[tx][ty]=0;
	}
	return ans;
}
main() 
{
	ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	cin>>n>>m;
	mag(); 
	cout<<ngm(1,1);
	
	
	
	
	
	
	
	
	return 0;
} 

2023/11/12 11:26
加载中...