hdu_problem_2046_骨牌铺方格

情况1:在n-1个格子后加一列,只能竖着放,所以是a[n-1]
情况2:在n-2个格子后加两列,只能横着放两个(竖着的属于第一种),所以是a[n-2]
在这里插入图片描述

/*
*
*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
*
*
*Author
*lcy
*
*
*Source
*递推求解专题练习(For Beginner)
*
*
*Recommend
*lcy
*
*/
#include<iostream>
using namespace std;
long long a[100] = { 0,1,2 };
void func() {
 for (int i = 3; i < 100; i++) {
  a[i] = a[i - 1] + a[i - 2];
 }
}
int main() {
 int n;
 func();
 while (cin >> n) {
  cout << a[n] << endl;
 }
 system("pause");
 return 0;
}

猜你喜欢

转载自blog.csdn.net/CoderMaximum/article/details/86292097