这题我使用的是dfs,本以为会轻轻松松的AC,和结果是1AC,4TLE,望各位大佬指点指点!
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char a[1005][1005];
bool vis[1005][1005];
void dfs(int x,int y)
{
if (x==n&&y==n)
{
ans++;
return ;
}
if (y+1<=n&&a[x][y+1]!='#'&&vis[x][y+1]==false)
{
vis[x][y+1]=true;
dfs(x,y+1);
vis[x][y+1]=false;
}
if (x+1<=n&&a[x+1][y]!='#'&&vis[x+1][y]==false)
{
vis[x+1][y]=true;
dfs(x+1,y);
vis[x+1][y]=false;
}
return ;
}
int main()
{
cin >> n >> m;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
a[i][j]='.';
for(int i=1; i<=m; i++)
{
int x,y;
cin >> x >> y;
a[x][y]='#';
}
dfs(1,1);
cout << ans%100003;
return 0;
}