POJ 2506
来源:互联网 发布:windows10数据恢复 编辑:程序博客网 时间:2024/06/05 16:09
TilingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8097 Accepted: 3921Description
In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? 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
2812100200Sample Output
317127318451004001521529343311354702511071292029505993517027974728227441735014801995855195223534251
#include<cstdio>#include<iostream>#include<cstring>using namespace std;char s[260][250];int main(){ int n,m,i,j,k; memset(s,'0',sizeof(s)); s[0][0]='1';s[1][0]='1',s[2][0]='3',s[3][0]='5'; for(i=4;i<=250;i++) { for(j=0;j<200;j++) { k=(2*(s[i-2][j]-'0')+s[i-1][j]-'0'+s[i][j]-'0');//之所以还要加上s[i][j],这是前一位向后一位的进位。 s[i][j]=k%10+'0'; s[i][j+1]=k/10+'0'; } } while(cin>>n) { int x=200; for(i=200;i>=0;i--) { if(s[n][i]!='0') { x=i; break; } } for(i=x;i>=0;i--) { printf("%c",s[n][i]); } cout<<endl; } return 0;}
方法二:
JAVA 过大数feel excellent!
import java.util.*;import java.io.*;import java.math.*;public class Main{static BigInteger[] ans;public static void main(String srga[]){Scanner cin=new Scanner(System.in);ans=new BigInteger[260];ans[0]=BigInteger.valueOf(1);ans[1]=BigInteger.valueOf(1);ans[2]=BigInteger.valueOf(3);int i;for(i=3;i<=255;i++){ans[i]=ans[i-1].add( ans[i-2].multiply(BigInteger.valueOf(2)) );}while(cin.hasNext()){int a;a=cin.nextInt();System.out.println(ans[a]);}cin.close();}}
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
- 6.28国际癫痫关爱日 昆明军海与你同行
- iOS 图片填充模式
- 开发框架选型
- matlab使用imhist、plot、fill画可填充颜色连续直方图
- 使用Cargo实现自动化部署
- POJ 2506
- 65.输出单向链表中节点上最大值
- jsp里input中获取当前时间,与WdatePicker配合使用
- phonegap打包及libCordova.a编译问题
- 勒索软件转战移动设备
- Selenium2.0功能测试之Alert/Confirm/Prompt的处理(Java版)
- Linux chmod命令详解
- mapReduce计算 最大值-----
- android ANR产生原因和解决办法