Tiling_easy version recursion

Tiling_easy version

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9503    Accepted Submission(s): 7266


Problem Description
There is a grid of size 2 xn, and now it needs to be covered with 2 sizes of dominoes, 2 x 1 and 2 x 2 respectively, please calculate how many ways there are in total.
 

Input
The first line of input contains a positive integer T (T<=20), indicating that there are a total of T groups of data, followed by T lines of data, each line contains a positive integer N (N<=30), indicating that the size of the grid is 2 rows and N columns.
 

Output
Output how many laying methods there are, and the output of each set of data occupies one line.
 

Sample Input
 
  
3 2 8 12
 

Sample Output
 
  
3 171 2731
 #include<iostream>
#include<cstdio>
using namespace std;
long long dp[37];
void f()
{
    dp[1]=1;
    dp[2]=3;
    for(int i=3;i<=30;i++)
        dp[i]=dp[i-1]+dp[i-2]*2;
}
int main()
{
    int t;
    int n;
    f();
    cin>>t;
    while(t--)
    {
        cin>>n;
        cout<<dp[n]<<endl;
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324855933&siteId=291194637