POJ
来源:互联网 发布:java中类与对象的关系 编辑:程序博客网 时间:2024/06/05 02:39
In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.
Here is a sample tiling of a 2x17 rectangle.
Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.
For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle.
2812100200
317127318451004001521529343311354702511071292029505993517027974728227441735014801995855195223534251
a[n]=2*a[n-2]+a[n-1];
#include <algorithm>#include <string.h>#include <iostream>#include <stdio.h>#include <string>#include <vector>#include <queue>#include <map>#include <set>using namespace std;typedef long long LL;const int N = 2010;int a[300][300];int main(){ memset(a,0,sizeof(a)); a[0][0]=1, a[1][0]=1,a[2][0]=3; int n; while(scanf("%d", &n)!=EOF) { if(n==2) cout<<3<<endl; else { int digit=1; for(int i=3; i<=n; i++) { int sum=0; for(int j=0; j<digit; j++) { a[i][j]=(sum+a[i-1][j]+2*a[i-2][j])%10000; sum=(sum+a[i-1][j]+2*a[i-2][j])/10000; } if(sum!=0) { a[i][digit++]=sum; } } cout<<a[n][digit-1]; for(int i=digit-2; i>=0; i--) printf("%04d",a[n][i]); cout<<endl; } } return 0;}
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- Markdown Test
- 前端开发小技巧
- Hadoop的WordCount实现
- 逻辑思维题
- IntelliJ IDEA——新建项目(模块)或导入项目(模块)
- POJ
- 为什么说全栈工程师是未来?| 长文多图
- 我的第一篇博客
- 数据结构之存储结构
- hdu #3507 Print Article(dp+斜率优化)
- Java学习笔记(二)封装的好处与垃圾回收机制的一些知识
- 封装802.1Q与 ISL的区别
- 顺序栈的基本操作
- Linux环境下GNU, GCC, G++编译器