1. 程式人生 > >hdu 2606 Renovation Problem(遞推)

hdu 2606 Renovation Problem(遞推)

【題目】

Renovation Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 753    Accepted Submission(s): 262

 

Problem Description

The New Year’s Day is comming ! Every family want to make theiir house looks more beautiful , so does Teddy’s . To make his own house looks different from other's , he went to the shop to buy four kinds of tiles . each kind of tiles has different size : 1*1 , 2*2 , 3*3 and 4 * 4, respectively .

The problem is , how many ways there are to tile his floor which has a area of 4*N using these four kinds of tiles ? You can assume that the number of each kind of tiles is enough.  

Input

The first line contain a T. followed by T lines ,each line contain a integer N.(1<=N <=100).

 

Output

For each case, output the ans % 19890907.

 

Sample Input

2

1

2

 

Sample Output

1

5

【思路】

遞推。

f(n)=f(n-1)+4*f(n-2)+2*f(n-3)+f(n-4)。

還有一種情況,我們用2*2的時候會產生一個交叉的情況,如下所示: 假設'.'表示磚塊,'1'表示未鋪的地板 4*3的地板情況: ..11          11.. ....    和     .... 11..           ..11 因為這兩種情況在n>=3的情況下每行都會出現,所以我們需要列舉一遍。

【程式碼】

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define go(i,a,b) for(int i=a;i<=b;i++)
#define og(i,a,b) for(int i=a;i>=b;i--)
const int inf=0x3f3f3f3f;
using namespace std;
typedef long long ll;
const int mod=19890907;
main()
{
    int n,t;
    int f[105];
    f[0]=1,f[1]=1,f[2]=5,f[3]=13;
    go(i,4,100)
    {
        f[i]=f[i-1];
        f[i]=(f[i]+f[i-2]*4)%mod;
        f[i]=(f[i]+f[i-3]*2)%mod;
        f[i]=(f[i]+f[i-4])%mod;
        go(k,3,i)
            f[i]=(f[i]+2*f[i-k])%mod;
    }
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",f[n]);
    }
}