For related knowledge points, please refer
to the DFS
DFS detailed explanation of the algorithm topic
Title: Grid Divide
a 6x6 grid and cut into two parts along the edge of the grid. The two parts are required to be exactly the same shape.
Including these 3 methods, how many different segmentation methods are there in total? Note: Rotational symmetry belongs to the same segmentation method.
Please submit this integer without any superfluous content or explanatory text.
#include<iostream>
#include<cstring>
using namespace std;
bool book[10][10];//记录状态数组
int cnt = 0;
void dfs(int x,int y)
{
int next[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};//定义方向数组,便于向四个方向拓展
int tx,ty;
if(x == 0 || y == 0 || x == 6 || y == 6)//判断边界
{
cnt++;//到达边界,数量加1
return ;
}
for(int k = 0 ; k <= 3 ; k++)//向四个方向拓展
{
tx = x + next[k][0];
ty = y + next[k][1];
if(book[tx][ty] == 1)//如果标记走过,跳出此次循环
continue;
book[tx][ty] = 1;
book[6 - tx][6 - ty] = 1;
dfs(tx,ty);//如果成立,在此点继续搜索
book[tx][ty] = 0;
book[6 - tx][6 - ty] = 0;
}
}
int main()
{
memset(book, 0,sizeof(book));
book[3][3] = 1;
dfs(3,3);//在中心点(3,3)开始拓展
cout << cnt / 4 << endl;//由于图形是中心对称,因此要除以4
}