网格的铺设问题——骨牌

版权声明:就是码字也不容易啊 https://blog.csdn.net/qq_40946921/article/details/84074170

Problem Description
有一个大小是 2 x n 的网格,现在需要用2种规格的骨牌铺满,骨牌规格分别是 2 x 1 和 2 x 2,请计算一共有多少种铺设的方法。

Input
输入的第一行包含一个正整数T(T<=20),表示一共有 T组数据,接着是T行数据,每行包含一个正整数N(N<=30),表示网格的大小是2行N列。

Output
输出一共有多少种铺设的方法,每组数据的输出占一行。

Sample Input
3
2
8
12

Sample Output
3
171
2731

#include <stdio.h>
#include<math.h>
int function(int n) {
	if (n == 1)
		return 1;
	if (n == 2)
		return 3;
	else
		return 2 * function(n - 2) + function(n - 1);
}
int main() {
	int n, tmp;
	scanf("%d", &n); 
	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		printf("%d\n", function(tmp));
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40946921/article/details/84074170