蓝桥杯2017-A组第4题:方块分割

题目描述:方格风格

6x6的方格,沿着格子的边线剪开成两部分。
要求这两部分的形状完全相同。

注意:旋转对称的属于同一种分割法。

如图所示

思路

去中间点为起点(3,3),分四个方向(上下左右),走一步就在mp数组中标记为1,在与起点中心对称的点也标记为1(例如:[2,2]与[4,4]),当走到x==0||x==6||y==0||y==6的时候结束,ans++。

最终结果为ans/4

代码

#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
int mp[7][7];
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
int ans = 0;
void solve(int x,int y)
{
    if(x==0||x==6||y==0||y==6)
    {
        ans++;
        return;
    }
    for(int i = 0;i<4;i++)
    {
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(mp[nx][ny])continue;
        mp[nx][ny] = 1;
        mp[6-nx][6-ny] = 1;
        solve(nx,ny);
        mp[nx][ny] = 0;
        mp[6-nx][6-ny] = 0;
    }
}
int main()
{
    mp[3][3] = 1;
    solve(3,3);
    printf("%d",ans/4);
    return 0;
}
posted @ 2020-07-29 19:27  9+JQK  阅读(146)  评论(0)    收藏  举报