zoukankan      html  css  js  c++  java
  • poj 2506 Tiling

    就是一个递推的题目,但是由于数据比较大,所以用到了大整数。

    递推方程F(n)=F(n-1)+2*F(n-2);

     1 #include<cstdio>
    2 #include<string.h>
    3 #include<iostream>
    4 using namespace std;
    5 #define N 10000
    6 int b[N],c[N],t[N];
    7 int re[260][N];
    8 struct node
    9 {
    10 int len;
    11 int re[N];
    12 }a[260];
    13 void ca()
    14 {
    15 int i,j;
    16 a[0].re[0]=1;
    17 a[1].re[0]=1;
    18 a[2].re[0]=3;
    19 a[0].len=a[1].len=a[2].len=1;
    20 b[0]=3;c[0]=1;
    21 int len1=1,len2=1;
    22 int len;
    23 for(i=3;i<=250;i++)
    24 {
    25 for(j=0;j<251;j++) a[i].re[j]=0;
    26 memset(t,0,sizeof(t));
    27 for(j=0;j<len2;j++)
    28 {
    29 t[j]+=c[j]*2;
    30 if(t[j]>9)
    31 {
    32 t[j+1]++;t[j]-=10;
    33 }
    34 }
    35 if(t[len2]) len2++;
    36 for(j=0;j<len2;j++)
    37 c[j]=t[j];
    38 len=len1>len2?len1:len2;
    39 for(j=0;j<len;j++)
    40 {
    41 a[i].re[j]+=(b[j]+c[j]);
    42 if(a[i].re[j]>9)
    43 {
    44 a[i].re[j+1]++;a[i].re[j]-=10;
    45 }
    46 }
    47 memset(c,0,sizeof(c));
    48 for(j=0;j<len1;j++)
    49 c[j]=b[j];
    50 len2=j;
    51 memset(b,0,sizeof(b));
    52 if(a[i].re[len]) len++;
    53 for(j=0;j<len;j++)
    54 b[j]=a[i].re[j];
    55 a[i].len=len1=j;
    56 }
    57 }
    58 int main()
    59 {
    60 int n,i;
    61 ca();
    62 while(cin>>n)
    63 {
    64 i=a[n].len;
    65 while(!a[n].re[i]) i--;
    66 while(i>=0) cout<<a[n].re[i--];
    67 cout<<endl;
    68 }
    69 return 0;
    70 }
  • 相关阅读:
    西藏之行的一点总结
    《吃的法则》总结
    《心法》总结
    分布式系统中的CAP、ACID、BASE概念
    《你当像鸟飞往你的山》总结
    《怪诞行为学》总结
    编程的一些抽象核心
    《活法》总结
    Mac使用Charles给iPhone抓包流程
    《认知天性》总结
  • 原文地址:https://www.cnblogs.com/fxh19911107/p/2380893.html
Copyright © 2011-2022 走看看