题目: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. MFC中CListCtrl类依靠CImageList贴图并显示不同图像

    只介绍主要方法,函数的具体参数可在MSDN上查阅 ------------------------------------------- CListCtrl     m_ListCtrl; CImag ...

  2. 详解 Cookie 和 Session 关系和区别

    在技术面试中,经常被问到“说说Cookie和Session的区别”,大家都知道,Session是存储在服务器端的,Cookie是存储在客户端的,然而如果让你更详细地说明,你能说出几点?今天个推君就和大 ...

  3. BFC 块级元素格式化上下文

    Block Formatting Contexts: 块级元素格式化上下文块级元素如何对它的内容(子元素:也是一个块元素)进行布局,以及与其它元素(与内容同级别)的关系和相互作用 普通文档流的布局规则 ...

  4. 「LibreOJ β Round #4」多项式 (广义欧拉数论定理)

    https://loj.ac/problem/525 题目描述 给定一个正整数 kkk,你需要寻找一个系数均为 0 到 k−1之间的非零多项式 f(x),满足对于任意整数 x 均有 f(x)modk= ...

  5. LightOJ 1070 - Algebraic Problem 推导+矩阵快速幂

    http://www.lightoj.com/volume_showproblem.php?problem=1070 思路:\({(a+b)}^n =(a+b){(a+b)}^{n-1} \) \(( ...

  6. JS中client/offset/scroll等的宽高解析

    原文地址:→传送门 window相关宽高属性 1. window.outerHeight (窗口的外层的高度) / window.outerWidth (窗口的外层的宽度) window.outerH ...

  7. PHP扩展--vld查看opcode代码

    vld安装 wget http://pecl.php.net/get/vld-0.13.0.tgz tar zxvf vld-0.13.0.tgz cd vld-0.13.0 /usr/local/p ...

  8. 重构改善既有代码设计--重构手法15:Remove Middle Man (移除中间人)

    某个类做了过多的简单委托动作.让客户直接调用受托类. 动机:在Hide Delegate (隐藏委托关系)的“动机”中,谈到了“封装委托对象”的好处.但是这层封装也是要付出代价的,它的代价是:每当客户 ...

  9. python学习笔记(十六)之文件

    打开文件用open函数 open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=Tru ...

  10. How to reset XiaoMi bluetooth headphone Youth edition.

    To reset the speaker 1. Long press the phone call button to shut off the speaker 2. Connect the char ...