'commit'
This commit is contained in:
38
TangDou/LanQiaoBei/LanQiaoBei13GuoSai/6.cpp
Normal file
38
TangDou/LanQiaoBei/LanQiaoBei13GuoSai/6.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#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
|
||||
*/
|
||||
Reference in New Issue
Block a user