骨牌铺方格(菲波那切数列)

Problem Description
在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
 
Input
输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。
 
Output
对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。
 
Sample Input
1 3 2
 
Sample Output
1 3 2
   
 1 #include<iostream>
 2 #include<iomanip>
 3 //#include<bits/stdc++.h>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<cstring>
 7 #include<algorithm>
 8 #include<sstream>
 9 #define PI  3.14159265358979
10 #define LL long long
11 #define  eps   0.00000001
12 using namespace std;
13 LL f[100];
14 LL solve(LL x)
15 {
16     if(f[x]) return f[x];
17     for(int i=4;i<=x;++i)
18     {
19         f[i]=f[i-1]+f[i-2];
20     }
21     return f[x];
22 }
23 int main()
24 {
25     int T;
26     f[1]=1,f[2]=2,f[3]=3;
27     while(cin>>T)
28     {
29         cout<<solve(T)<<endl;
30     }
31 
32 }
View Code
原文地址:https://www.cnblogs.com/Auroras/p/10806184.html