2017D 方格分割

http://oj.ecustacm.cn/problem.php?id=1320

#include <cstdio>
#include <cstring>
using namespace std;

int dir[4][2] = {0,1, 0,-1, 1,0, -1,0};
int vis[10][10];
int ans = 0;
void dfs(int x, int y){
    if(x == 0 || y == 0 || x == 6 || y == 6){
        ans++;
        return ;
    }
    for(int i = 0; i < 4; i++){
        int x1 = x + dir[i][0];
        int y1 = y + dir[i][1];

        int x2 = 6 - x1;
        int y2 = 6 - y1;

        if(x1 >= 0 && y1 >= 0 && x1 <= 6 && y1 <= 6){
            if(!vis[x1][y1]){
                vis[x1][y1] = vis[x2][y2] = 1;
                dfs(x1,y1);
                vis[x1][y1] = vis[x2][y2] = 0;
            }
        }
    }
}


int main(){

    vis[3][3] = 1;
    dfs(3,3);
    printf("%d
",ans/4);

    return 0;
}

刚开始不明白为什么是0和6,看了遍题目剪开,自己画图,线是0到6

原文地址:https://www.cnblogs.com/xcfxcf/p/12708501.html