首页 > 其他 > 详细

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

时间:2019-05-03 20:56:31      阅读:103      评论:0      收藏:0      [点我收藏+]
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!