我感觉到了是dfs,但是我不是很会搞它(2017年题好难啊!!!)
本小白以为也是跟以前的连通块似的,按格子来找坐标
后来发现不太行
而且一定要注意根据对称性会有四个是一样的,如果按格子来的话很难判断
所以这个题是看分割线的
从中心点往左走,然后右边的也一起标记(因为对称)
最后的答案要除以4,因为对称
注意:
这个题找完一组别忘置零(回溯?)
1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #include<string> 8 #include<vector> 9 #include<queue> 10 #include<map> 11 #include<set> 12 using namespace std; 13 14 #define N 6 15 int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; 16 int vis[10][10]; 17 int ans=0; 18 19 void dfs(int x,int y) 20 { 21 if(x==0||x==N||y==0||y==N) 22 { 23 ans++; 24 return; 25 } 26 for(int i=0;i<4;i++) 27 { 28 int dx=x+dir[i][0]; 29 int dy=y+dir[i][1]; 30 if(dx>=0&&dx<=N&&dy>=0&&dy<=N&&!vis[dx][dy]) 31 { 32 vis[dx][dy]=1; 33 vis[N-dx][N-dy]=1; 34 dfs(dx,dy); 35 vis[dx][dy]=0;//找完一组,挨个置零 36 vis[N-dx][N-dy]=0; 37 } 38 39 } 40 } 41 int main() { 42 vis[N / 2][N / 2] = 1; 43 dfs(N / 2, N / 2); 44 cout << ans / 4 << endl; 45 return 0; 46 }