UVA 10918 Tri Tiling

题意:求几种方法构建成3*n的矩形,小的矩形只有1*2的,仿照uva 10359的思路f(n)=3*f(n-2)+2*f(n-4),递推出公式:f(n)=4*f(n-2)-f(n-4),当n是奇数的时候,f(n)=0

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100;

int f[MAXN];

int main(){
    f[0] = 1;
    f[1] = 0;
    f[2] = 3;
    for (int i = 3; i < MAXN; i++){
        if (i & 1)
            f[i] = 0;
        else f[i] = 4 * f[i-2] - f[i-4];
    }
    int n;
    while (scanf("%d",&n) != EOF && n != -1)
        printf("%d\n",f[n]);
    return 0;
}


你可能感兴趣的:(UVA 10918 Tri Tiling)