http://acm.hdu.edu.cn/showproblem.php?pid=2501
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
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
要找n*2有几种方式: 因为只有2*1和2*2的木块,所以就要看n-1 *2 和 n-2 *2 有几种,很容易推出
f ( n ) = f ( n-1 )(只有一种) + 2 * f ( n-2 );
做完可以做做这道:http://blog.csdn.net/yuzhiwei1995/article/details/47909635
#include<stdio.h>
#include<string.h>
int a[40];
void fun()
{
a[0]=1;
a[1]=1;
a[2]=3;
for(int i=3;i<=40;++i)
{
a[i] = a[i-1] + 2 * a[i-2];
}
}
int main()
{
int n;
int T;
fun();
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%d\n",a[n]);
}
return 0;
}