ZCMU—1159
来源:互联网 发布:赵薇 利益集团 知乎 编辑:程序博客网 时间:2024/06/05 17:19
1159: Tiling a Grid With Dominoes
Time Limit: 1 Sec Memory Limit: 128 MB[Submit][Status][Web Board]
Description
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.
Input
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.
Output
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.
Sample Input
Sample Output
【分析】
#include <stdio.h>#include <string.h>int dp[30][30];void dfs(int s,int ss,int p,int dep){ if(p>3) { dp[dep+1][ss]+=dp[dep][s]; return; } if(s&(1<<p)) dfs(s,ss,p+1,dep); else { dfs(s,ss|(1<<p),p+1,dep); if(p<=2&&!(s&(1<<(p+1)))) dfs(s,ss,p+2,dep); } } int main() { int i,j,n,t,cas=1; memset(dp,0,sizeof dp); dp[0][0]=1; for(i=0;i<25;i++) for(j=0;j<16;j++) if(dp[i][j]) dfs(j,0,0,i); scanf("%d",&t); while(t--) { scanf("%d",&n); printf("%d %d\n",cas++,dp[n][0]); } return 0; }
- ZCMU—1159
- ZCMU—1678
- ZCMU—1605
- ZCMU—1067
- ZCMU—1607
- ZCMU—1069
- ZCMU—1611
- ZCMU—1606
- ZCMU—1774
- ZCMU—1766
- ZCMU—1752
- ZCMU—1724
- ZCMU—1623
- ZCMU—1689
- ZCMU—1667
- ZCMU—1639
- ZCMU—1668
- ZCMU—1540
- Android编程思想,面向对象程序设计第一篇——设计模式6个原则
- ns2.34添加mflood协议(泛洪协议)
- 数据结构期末总结
- dubbo分布式搭建
- [IDE工具配置]myeclipse 2014 专业版 安装 svn插件
- ZCMU—1159
- 使用Toolbar + DrawerLayout快速实现高大上菜单侧滑
- java取出一个数组中第二大的数字
- php之坑--bindParam与bindValue
- oracle job 定时执行 存储过程
- 阿里云、Amazon、Google云数据库方案架构与技术分析
- gt-itm模型生成拓扑结构
- 文件夹下文件重新排序
- 1613-3-傅溥衍 总结《2016年12月12日》【连续第七十三天总结】