poj--2506
来源:互联网 发布:网页游戏发布平台源码 编辑:程序博客网 时间:2024/06/05 15:41
Tiling
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8319 Accepted: 4012
Description
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
Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.
Output
For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle.
Sample Input
2812100200
Sample Output
3
171
2731
845100400152152934331135470251
1071292029505993517027974728227441735014801995855195223534251
题目大意:计算要铺一个2xn的地板,只能用2x1,2x2的瓷砖,问有几种方法铺这个地板。
考查点:高精度加法。
核心思想:通过枚举一些情况,我们可以得到一个规律,2xn=2x(n-1)+2倍的 2x(n-2);接下来我们就可以用一个二维数组存储n从0到250每一种情况的答案。
代码如下:
#include<stdio.h>#include<string.h>int a[260][1000];int main(){int n,m,p,i,j,l;memset(a,0,sizeof(a));a[0][0]=1;a[1][0]=1; a[2][0]=3;a[3][0]=5;p=0; int k=1;for(i=4;i<=250;i++){ p=0;//p表示进位 l=k; for(j=0;j<l;j++) { a[i][j]=2*(a[i-2][j])+a[i-1][j]+p; p=a[i][j]/10; a[i][j]=a[i][j]%10; } while(p) { a[i][j]=p%10; p=p/10; j++; } k=j;}while(scanf("%d",&n)!=EOF){for(i=80;i>=0;i--){if(a[n][i]!=0)break;}for(j=i;j>=0;j--){printf("%d",a[n][j]);}printf("\n");}return 0;}
0 0
- poj 2506
- poj 2506
- poj 2506
- POJ 2506
- poj 2506
- POJ 2506
- poj--2506
- poj 2506
- poj 2506
- POJ 2506
- POJ 2506 Tiling
- POJ 2506 Tilling
- poj 2506Tiling
- POJ 2506 递归 + 高精度
- Poj 2506 Tiling
- POJ 2506 Tiling
- POJ 2506 -TILING
- POJ 2506 Tiling
- 字符串和编码
- HDU Cut Pieces (计数+求逆元)
- Android debug.keystore的密码
- ionic + angularJS $ionicHistory接口文档
- android stuido插件
- poj--2506
- 配置Tomcat
- layoutSubviews 调用
- hdu 5410
- 无需Root也能Hook?——Depoxsed框架演示
- 数据库SQL Server2012笔记(六)——修改表、数据的备份和恢复
- JAVA开发类似冒险岛的游戏Part1
- Android的输入事件分发机制笔记
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1)(组合数学+容斥)