Blue Bridge Cup Daily One Question 1.6 2017 Provincial Competition Group A 4. Grid Division [DFS]

Title description

Cut a 6x6 grid into two parts along the edge of the grid. The shapes of the two parts are required to be exactly the same. The figure shows the feasible division method.  
 
Try to calculate: Including these three division methods, how many different division methods are there in total? Note: Rotational symmetry belongs to the same division method. 

Output

Output an integer to indicate the answer 

https://blog.csdn.net/weixin_43914593/article/details/112257103

✬✬✬✬✬How to associate DFS from the divided grid? ✬✬✬✬✬

highlight:

1. Because the rotational symmetry belongs to the same division method, the result obtained is /4

2. According to the meaning of the question, this cutting line must pass through the center point of the figure. Once we have determined half of the dividing line that reaches the boundary, we can draw the other half based on this half of the symmetry. (So ​​you can search from the center point)

3. In the search process, it should be noted that the half of the dividing line we searched cannot pass through two points that are symmetric about the center at the same time. Therefore, when marking, you need to mark the symmetrical point as well. (Vis[x][y]=true while vis[6-x][6-y]=true)

4. Right, left, up, down, four directions are DFS.

int X[]={0,-1,1,0,0};

int Y[]={0,0,0,-1,1};

x+=X[i];

y+=Y[i];

mistakes:

1. Recursion in the for loop

2. After taking a step, come and ask if you have visited this point

for ( int i = 1; i <= 4; i++){ // four directions

        x += X[i]; y += Y[i]; //take a step

        if (!vis[x][y]){ // If the point is not visited, continue to search

            vis[x][y] = true ; // The current point is marked as visited

            vis[6 - x][6 - y] = true;

            dfs(x, y); // continue to search

            vis [6 - x] [6 - y] = false ;

            vis [x] [y] = false ;

        }

        x -= X[i]; y -= Y[i];

    }

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 110000;

int X[]={0,-1,1,0,0};
int Y[]={0,0,0,-1,1};

bool vis[10][10];
int ans=0;

void dfs(int x,int y)
{
    if(x==0||x==6||y==0||y==6)
    {
        ans++;
        return ;
    }
    for(int i=1;i<=4;i++)
    {
        x+=X[i];
        y+=Y[i];
        if(!vis[x][y])
        {
            vis[x][y]=true;
            vis[6-x][6-y]=true;
            dfs(x,y);
            vis[6-x][6-y]=false;
            vis[x][y]=false;
        }
        x-=X[i];
        y-=Y[i];
    }
}

int main()
{
    vis[3][3]=true;
    dfs(3,3);
    cout<<ans/4;
    return 0;
}


 

Guess you like

Origin blog.csdn.net/qq_43660826/article/details/112982567