You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
778 B

#include <bits/stdc++.h>
using namespace std;
const int N = 15;
typedef pair<int, int> PII;
int n, m;
int res;
int dx[] = {-1, 0, 1, 0}; // 上右下左
int dy[] = {0, 1, 0, -1}; // 上右下左
int st[N][N];
void dfs(int x, int y, int cnt) {
if (x == 1 && y == 1 && cnt == m * n) {
res++;
return;
}
for (int i = 0; i < 4; i++) {
int tx = x + dx[i], ty = y + dy[i];
if (tx == 0 || tx > n || ty == 0 || ty > m) continue;
if (!st[tx][ty]) {
st[tx][ty] = 1;
dfs(tx, ty, cnt + 1);
st[tx][ty] = 0;
}
}
}
int main() {
cin >> n >> m;
dfs(1, 1, 0);
printf("%d\n", res);
return 0;
} /**
测试数据:
3 4
答案:
4
*/