solution.cpp 655 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include <iostream>
using namespace std;

int ans;
int dire[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int vis[7][7];
void dfs(int x, int y)
{
    if (x == 0 || y == 0 || x == 6 || y == 6)
    {
        ans++;
        return;
    }

    vis[x][y] = 1;

    vis[6 - x][6 - y] = 1;
    for (int k = 0; k < 4; k++)
    {
        int nx = x + dire[k][0];
        int ny = y + dire[k][1];

        if (nx < 0 || nx > 6 || ny < 0 || ny > 6)
            continue;
        if (!vis[nx][ny])
        {
            dfs(nx, ny);
        }
    }
    vis[x][y] = 0;
    vis[6 - x][6 - y] = 0;
}
int main()
{
    dfs(3, 3);
    cout << ans / 4 << endl;
    return 0;
}