http://oj.ecustacm.cn/problem.php?id=1317
好吧,刚开始这道题真的摸不到头脑,不知道啥意思,后来一看题解才发现就是简单的暴力。
果真还是刷的题少,见的题型少。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
string a[]=
{
"UDDLUULRUL",
"UURLLLRRRU",
"RRUURLDLRD",
"RUDDDDUUUU",
"URUDLLRRUU",
"DURLRLDLRL",
"ULLURLLRDU",
"RDLULLRDDD",
"UUDDUDUDLL",
"ULRDLUURRR"
};
int ans;
bool map[15][15];
void dfs(int x,int y)
{
if(x>9||x<0||y>9||y<0)//过界,说明可以出来
{
ans++;
return ;
}
if(map[x][y]) return;//走过了,又回来了
map[x][y]=true;
if(a[x][y]=='U')
dfs(x-1,y);
if(a[x][y]=='D')
dfs(x+1,y);
if(a[x][y]=='L')
dfs(x,y-1);
if(a[x][y]=='R')
dfs(x,y+1);
}
int main(void)
{
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
memset(map,0,sizeof map);
dfs(i,j);
}
}
cout<<ans<<endl;
return 0;
}