在课堂上,我们分析了棋盘覆盖问题,同学们也看了我的程序运行的情况,今天我们来看一下另外一个覆盖问题。今天的问题是这样的:用n个2X1的矩形(这种矩形我们以后称之为骨牌或多米诺)覆盖2Xn的棋盘,有多少种不同的覆盖法?
Input
本问题有多组测试数据,对于每一组测试数据,输入只有一行n(意义如上所述,1<=n<=45)。
Output
对于每一组输入,输出也只有一行,即覆盖的方法种数。
Sample Input
1
2
Sample Output
1
2
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[50];
int main()
{
a[1]=1;
a[2]=2;
for(int i=3;i<=45;i++)
{
a[i]=a[i-1]+a[i-2];
}
int n;
while(cin>>n)
{
cout<<a[n]<<endl;
}
return 0;
}