solution.cpp 729 字节
Newer Older
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 39 40 41 42 43
#include <bits/stdc++.h>
using namespace std;
int chess[55][55], book[55][55];
int n, m, cnt = 0;
int dx[4] = {1, 0};
int dy[4] = {0, 1};

int judge(int x, int y)
{
    if (x % 2 == 0 && y % 2 == 0)
        return 0;
    return 1;
}

void dfs(int x, int y)
{
    if (x == n && y == m)
    {
        cnt++;
        return;
    }

    book[1][1] = 1;
    for (int i = 0; i < 2; i++)
    {
        int tx = x + dx[i];
        int ty = y + dy[i];
        if (tx >= 1 && tx <= n && ty >= 1 && ty <= m && judge(tx, ty) && book[tx][ty] == 0)
        {
            book[tx][ty] = 1;
            dfs(tx, ty);
            book[tx][ty] = 0;
        }
    }
}

int main()
{
    cin >> n >> m;
    dfs(1, 1);
    cout << cnt;
    return 0;
}