一定要在搜索完一个点后,重置状态数组
#include<bits/stdc++.h>
using namespace std;
int ans;
string a[]=
{"UDDLUULRUL",
"UURLLLRRRU",
"RRUURLDLRD",
"RUDDDDUUUU",
"URUDLLRRUU",
"DURLRLDLRL",
"ULLURLLRDU",
"RDLULLRDDD",
"UUDDUDUDLL",
"ULRDLUURRR"
};
bool v[11][11];
void dfs(int x,int y){
if(x<0 || x>9 || y<0 || y>9){
ans++;return ;
}
if(v[x][y]) return;
v[x][y]=1;
if(a[x][y]=='U') dfs(x-1,y);
if(a[x][y]=='R') dfs(x,y+1);
if(a[x][y]=='D') dfs(x+1,y);
if(a[x][y]=='L') dfs(x,y-1);
}
int main(){
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
dfs(i,j);
memset(v,0,sizeof(v));//重置访问数组
}
}
cout<<ans<<endl;
return 0;
}