poj2663

递推,注意f[0] = 1;

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

#define maxn 31

int main()
{
// freopen("t.txt", "r", stdin);
int f[maxn] = {1,0,3,0};
for (int i = 4; i < maxn; i++)
{
f[i]
= f[i - 2] * 3;
for (int j = 4; i - j >= 0; j += 2)
f[i]
+= f[i - j] * 2;
}
int n;
while (scanf("%d", &n), n != -1)
printf(
"%d\n", f[n]);
return 0;
}

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