Hat's Fibonacci(大数,好)
2024-08-30 12:37:51
Hat's Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9394 Accepted Submission(s): 3065
Problem Description
A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)
Your task is to take a number as input, and print that Fibonacci number.
Input
Each line will contain an integers. Process to end of file.
Output
For each case, output the result in a line.
Sample Input
100
Sample Output
4203968145672990846840663646
题解:大数相加超内存,所以想着每个里面存8位;输出的时候不足8位补0;
代码:
#include<stdio.h>
#include<string.h>
const int MAXN=;
const int MAXM=;
char temp[MAXN];
int dp[MAXN][];
int main(){
dp[][]=;
dp[][]=;
dp[][]=;
dp[][]=;
dp[][]=;
for(int i=;i<=;i++){
for(int j=;j<=;j++)dp[i][j]=dp[i-][j]+dp[i-][j]+dp[i-][j]+dp[i-][j];
for(int j=;j<=;j++)
if(dp[i][j]>MAXM)dp[i][j+]+=dp[i][j]/MAXM,dp[i][j]%=MAXM;
}
int n;
while(~scanf("%d",&n)){
int j=;
while(!dp[n][j])j--;
printf("%d",dp[n][j]);
while(--j>=)printf("%08d",dp[n][j]);//不足8位补零
puts("");
}
return ;
}
最新文章
- jQuery遍历checkbox
- 2014ACM/ICPC亚洲区北京站
- Mybatis学习记录
- Codeforces 740C. Alyona and mex 思路模拟
- 3D 矩阵旋转
- 极域电子教室 e-Learning Class V4 2010专业版 学生机 卸载方法
- SGU 194 Reactor Cooling Dinic求解 无源无汇有上下界的可行流
- 使用GO语言灵活批量ssh登录服务器执行操作
- Lucene索引的初步创建
- 关于material和sharedMaterial的问题
- CentOS 6.4 U盘启动盘制作、安装及遇到的问题解决
- XML 学习之保存节点
- I/O概述和审查操作
- 鸟哥Linux学习笔记03
- Vs Code 插件配置教程
- VSCode插件开发全攻略(八)代码片段、设置、自定义欢迎页
- SHELL脚本--多命令逻辑执行顺序
- mysql限制用户只能访问指定数据库
- 6月16 ThinkPHP连接数据库及Model数据模型层--------查询及数据添加
- Struts 2(二)
热门文章
- 论山寨手机与Android联姻 【1】MTK亮相的历史背景
- 最全面 Nginx 入门教程 + 常用配置解析
- 普林斯顿大学算法课 Algorithm Part I Week 3 求第K大数 Selection
- Windows SVN变更发送邮件通知(JAVA实现)
- 全国计算机等级考试二级教程-C语言程序设计_第15章_位运算
- SPOJ 1435 - Vertex Cover(树形DP,树的最小点覆盖)
- Android平台音频信号FFT的实现
- Windows消息传递函数SendMessage参数属性
- 关于我和document.write那点不得不说的事
- 关于vs启动调试报错:CS0016: 未能写入输出文件“xxxxxxxx”--“目录名称无效。”解决方法