骨牌铺方格
Time Limit: 1000 ms
Memory Limit: 32768 KiB
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
Hint
01 | #include<iostream> |
02 | #include<algorithm> |
03 | using namespace std; |
04 | int main() |
05 | { |
06 | long long a[100]; |
07 | a[1] = 1; |
08 | a[2] = 2; |
09 | int n; |
10 | while (cin>>n) |
11 | { |
12 | if (n<=2) |
13 | cout<<a[n]<<endl; |
14 | else |
15 | { |
16 | for ( int i=3;i<=n;++i) |
17 | { |
18 | a[i] = a[i-1] + a[i-2]; |
19 | } |
20 | cout<<a[n]<<endl; |
21 | } |
22 |
23 | } |
24 | return 0; |
25 | } |