题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865

本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是,f(1)=1,f(2)=2,f(3)=3,f(4)=5,f(5)=8,所以猜测,递推关系式为:

f(n)=f(n-1)+f(n-2),n>=3,f(1)=1,f(2)=2;

序列长度不超过200,即n的值不超过200,则估计f(n)的值得位数不超过1000位.在代码中,我们采用10000进制的方法,将数字f(...)的结果记录在数组中,每个数组元素可以存8位数.

与本题同类型的题目:http://blog.csdn.net/ten_sory/article/details/60883746

C++代码如下:

#include<iostream>
#include<string>
#include<string.h>
using namespace std; #define maxn 200 + 1
#define len 100
int a[maxn][len]; int main()
{
int i,j;
for(i=1;i<maxn;i++)
memset(a[i],0,sizeof(a[i]));
a[1][len-1] = 1;
a[2][len-1] = 2;//都是len-1 for(i=3;i<maxn;i++)
{
int c = 0;
for(j=len-1;j>=0;j--)
{
c += (a[i-1][j]+a[i-2][j]);
a[i][j] = c % 100000000;
c /= 100000000;
}
} string s;
int T;
scanf("%d",&T);
while(T--)
{
cin >> s;
int n = s.length();
if(n==1)
printf("%d\n",1);
else if(n==2)
printf("%d\n",2);
else
{
for(i=0;i<len;i++)
if(a[n][i])
break;
printf("%d",a[n][i]);
for(j=i+1;j<len;j++)
printf("%08d",a[n][j]);
printf("\n");
}
} return 0;
}

上述代码,提交可以通过.

【hdoj_1865】1sting(递推+大数)的更多相关文章

  1. Tiling(递推+大数)

    Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...

  2. Children’s Queue HDU 1297 递推+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...

  3. ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)

    Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...

  4. poj 2506 Tiling(递推 大数)

    题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...

  5. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  6. ACM学习历程—HDU1023 Train Problem II(递推 && 大数)

    Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know  ...

  7. UVA11375火柴(递推+大数)

    题意:       给你n根火柴,问你能组成多少种数字,比如3根可以组成1或者7,组成的数字中不能有前导0, 思路:       我们开一个数组,d[i]记录用i跟火柴可以组成多少种数字,则更新状态是 ...

  8. Tiling 简单递推+大数

    Tiling c[0]=1,c[1]=1,c[2]=3;   c[n]=c[n-1]+c[n-2]*2;   0<=n<=250.   大数加法 java  time  :313ms 1 ...

  9. HDU1134/HDU1133 递推 大数 java

    Game of Connections Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. 2656: [Zjoi2012]数列(sequence)(递归+高精度)

    好久没写题了T T NOIP 期中考双血崩 显然f(x)=f(x>>1)+f((x>>1)+1),考虑每次往x>>1递归,求出f(x),复杂度O(logN) 我们设 ...

  2. Codeforces 585.D Lizard Era: Beginning

    D. Lizard Era: Beginning time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. java面试之闭包(closure)

    今天在学习Openresty的时候回顾了下闭包这个问题,感觉很久没有深入的了解这块的内容的,只是之前js的时候学习过闭包,突然一问,感觉不记得闭包了: 看了一个比较有趣的答案: 闭包,顾名思义,就是把 ...

  4. C++并发编程 互斥和同步

    C++并发编程 异步任务(async) 线程基本的互斥和同步工具类, 主要包括: std::mutex 类 std::recursive_mutex 类 std::timed_mutex 类 std: ...

  5. duilib CDateTimeUI 在Xp下的bug修复

    转自:http://my.oschina.net/u/343244/blog/370131 CDateTimeUI 的bug修复.修改CDateTimeWnd的HandleMessage方法 ? 1 ...

  6. Java设计模式の模版方法模式

    概述 模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑.不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的 ...

  7. 2017北京国庆刷题Day6 afternoon

    期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...

  8. Python学习笔记(三十九)— 内置模块(8)XML基础

    摘抄自:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001432002075 ...

  9. laravel 重定向路由带参数

    转载: http://www.cnblogs.com/foreversun/p/5642176.html 举例: 路由: //任务列表页 $router->get('/taskDetail/{i ...

  10. call_user_func 具体使用方法,实例说明

    <?php class Person{ public $name="jack"; public static function say(){ echo "ok&qu ...