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
找规律。
题目:
[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 ); } }
相关文章推荐
- POJ-1465 Multiple
- Google发布机器学习平台Tensorflow游乐场~带你玩神经网络
- 用训练好的caffemodel来进行分类
- jsp 自定义标签
- C++ 虚函数、纯虚函数、抽象类、接口、虚基类
- (LeetCode)Bulls and Cows --- 数字匹配问题
- SQL Server 连接超时案例一则
- CodeForces 445B - DZY Loves Chemistry(并查集)
- 乱码文件名处理(删除、重命名)
- Catch That Cow
- nyoj 737 石子合并(一) 区间动规
- 求两圆环相交部分的面积
- UITableview Plain风格下 SectionHeader悬浮问题
- [转]股票买卖
- maven打包本地文件jar
- tomcat启动不了 报异常java.lang.ClassNotFoundException
- 涉密计算机检查工具
- java韩顺平老师视频有需要可以留言
- 一个故事帮你理解线程和线程池
- 2016夏季练习——KMP