传送门
代码:
#include<stdio.h>
#include <cstring>
using namespace std;
int n, m,sum=0;
int a[30][60];
void DFS(int x, int y, int step) {
if (step == n) {
sum++;
return;
}
a[x][y] = 1;
if (!a[x][y - 1])DFS(x, y - 1, step + 1);
if (!a[x][y + 1])DFS(x, y + 1, step + 1);
if (!a[x + 1][y])DFS(x + 1, y, step + 1);
a[x][y] = 0;
}
int main() {
while (~scanf("%d", &n)) {
sum = 0;
memset(a, 0, sizeof(a));
DFS(0, 26, 0);
printf("%d\n", sum);
}
}