【hdoj_1865】1sting(递推+大数)
题目: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(递推+大数)的更多相关文章
- Tiling(递推+大数)
Description In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles? Here is a sample tili ...
- Children’s Queue HDU 1297 递推+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1297 题目大意: 有n个同学, 站成一排, 要求 女生最少是两个站在一起, 问有多少种排列方式. 题 ...
- ACM学习历程—HDU1041 Computer Transformation(递推 && 大数)
Description A sequence consisting of one digit, the number 1 is initially written into a computer. A ...
- poj 2506 Tiling(递推 大数)
题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...
- Buy the Ticket HDU 1133 递推+大数
题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元, m个人是只有50元一张的, n个人 ...
- ACM学习历程—HDU1023 Train Problem II(递推 && 大数)
Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know ...
- UVA11375火柴(递推+大数)
题意: 给你n根火柴,问你能组成多少种数字,比如3根可以组成1或者7,组成的数字中不能有前导0, 思路: 我们开一个数组,d[i]记录用i跟火柴可以组成多少种数字,则更新状态是 ...
- 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 ...
- HDU1134/HDU1133 递推 大数 java
Game of Connections Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
随机推荐
- [POI2005]Bank notes
link 试题分析 我们发现此题是一个十分简单的多重背包.但是按照朴素写法会超时.所以要去考虑优化. 我们发现我们若$W=7$,可以拆成$1+2+4$,不用每次$1+1+1+1+1+1+1$,从$N$ ...
- 题解【bzoj3529 [SDOI2014]数表】
Description \(T\) 组询问,定义 \(F(n)=\sum\limits_{d|n}d\).每次给出 \(n,m,a\) 求 \[\sum\limits_{i=1,j=1,F(\gcd( ...
- 使用uiautomator时遇到问题的处理方法
本帖持续更新中… 一.使用adb devices无法连接到模拟器 这种情况可能是因为服务挂了之类的原因,重启一下服务 adb kill-server //关闭adb服务 adb start-serve ...
- python入门篇之介绍和流程控制(一)
Python入门 一.第一句python代码 很多语言的第一句python代码都是以“你好,世界”开始的,那么我们的python也是如此. 在 /home/dev/ 目录下创建 hello.py 文件 ...
- python 获取外网地址
def get_ip(): try: url = "http://cn.bing.com/search?q=ip&go=%E6%8F%90%E4%BA%A4&qs=n& ...
- Hadoop 遇到的问题集
1. Mac 使用ssh命令无法成功 ssh localhost,但是可以ssh其他的 可能原因:ssh服务未启动 解决方法: 1.启动sshd服务: sudo launchctl load -w / ...
- 树上的构造 树分治+树重心的性质 Codeforces Round #190 (Div. 2) E
http://codeforces.com/contest/322/problem/E E. Ciel the Commander time limit per test 1 second memor ...
- 【CodeForces】914 H. Ember and Storm's Tree Game 动态规划+排列组合
[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsn ...
- 【BZOJ】2120: 数颜色 带修改的莫队算法
[题意]给定n个数字,m次操作,每次询问区间不同数字的个数,或修改某个位置的数字.n,m<=10^4,ai<=10^6. [算法]带修改的莫队算法 [题解]对于询问(x,y,t),其中t是 ...
- XML & JSON---iOS-Apple苹果官方文档翻译
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong //转载请注明出处--本文永久链接 ...