您的位置:首页 > 其它

hdu 1992 Tiling a Grid With Dominoes

2016-07-25 10:37 453 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1992
题目:
[align=left]Problem Description[/align]
We wish to tile a grid 4 units high and N units long with rectangles (dominoes) 2 units by one unit (in either orientation). For example, the figure shows the five different ways that a grid 4 units high and 2 units wide may be tiled.



Write a program that takes as input the width, W, of the grid and outputs the number of different ways to tile a 4-by-W grid.

 

[align=left]Input[/align]
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset contains a single decimal integer, the width, W, of the grid for this problem instance.

 

[align=left]Output[/align]
For each problem instance, there is one line of output: The problem instance number as a decimal integer (start counting at one), a single space and the number of tilings of a 4-by-W grid. The values of W will be chosen so the count
will fit in a 32-bit integer.

 

[align=left]Sample Input[/align]

3
2
3
7

 

[align=left]Sample Output[/align]

1 5
2 11
3 781

找规律。
#include <iostream>
#include<cstdio>

using namespace std;

int d[23]={1,1,5,11};

int main()
{
for(int i=4;i<23;i++)   d[i]=d[i-1]+5*d[i-2]+d[i-3]-d[i-4];
int T;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
int n;
scanf("%d",&n);
printf("%d %d\n",k,d
);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: