1018骨牌铺方格(分治算法)

Description

在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:

Input

输入包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0< n<=50)。

Output

输出铺放方案的总数。

Sample

Input 

3

Output 

3

Hint

hdoj2046 有链接提示的题目请先去链接处提交程序,AC后提交到SDUTOJ中,以便查询存档。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string>
 4 #include <string.h>
 5 #include <algorithm>
 6 #include <math.h>
 7 #include <map>
 8 #include <vector>
 9 
10 using namespace std;
11 
12 int main()
13 {
14     long long n, i, a[55];
15     a[0] = 0;
16     a[1] = 1;
17     a[2] = 2;
18     for(i=3; i<=52; i++)
19     {
20         a[i] = a[i-1] + a[i-2];
21     }
22     while(cin >> n)
23     {
24         cout << a[n] << endl;
25     }
26     return 0;
27 }
原文地址:https://www.cnblogs.com/0xiaoyu/p/14089697.html