poj3036

记忆化搜索

View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;

int f[] = {1, 0, 6, 12, 90, 360, 2040, 10080, 54810, 290640, 1588356, 8676360, 47977776, 266378112, 1488801600};
int n;

int main()
{
//freopen("t.txt", "r", stdin);
int t;
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
printf("%d\n", f[n]);
}
return 0;
}
//#include <iostream>
//#include <cstdlib>
//#include <cstring>
//#include <cstdio>
//using namespace std;
//
//int f[100][100][20];
//
//int cal(int x, int y, int step)
//{
// if (f[x][y][step])
// return f[x][y][step];
// if (step == 0)
// return x == 50 && y == 50;
// f[x][y][step] += cal(x + 1, y + 1, step - 1);
// f[x][y][step] += cal(x + 1, y, step - 1);
// f[x][y][step] += cal(x, y + 1, step - 1);
// f[x][y][step] += cal(x - 1, y - 1, step - 1);
// f[x][y][step] += cal(x - 1, y, step - 1);
// f[x][y][step] += cal(x, y - 1, step - 1);
// return f[x][y][step];
//}
//
//int main()
//{
// freopen("t.txt", "r", stdin);
// for (int i = 2; i < 14; i++)
// printf("%d,", cal(50, 50, i));
// return 0;
//}

原文地址:https://www.cnblogs.com/rainydays/p/2203551.html