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.
 
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 ;
}

Hat's Fibonacci(大数,好)的更多相关文章

  1. HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  2. 【hdoj_1250】Hat's Fibonacci(大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1250 思路:本题的Fibonacci数列是扩展的四阶的Fibonacci数列,用递推关系式求解即可. 题目 ...

  3. Hat's Fibonacci(大数加法+直接暴力)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 M ...

  4. HDU 1250 Hat's Fibonacci(大数相加)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...

  5. HDU 1250 Hat's Fibonacci (递推、大数加法、string)

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. hdu 1250 Hat's Fibonacci

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...

  7. HDUOJ----1250 Hat's Fibonacci

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. (二维数组 亿进制 或 滚动数组) Hat's Fibonacci hdu1250

    Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1250 Hat's Fibonacci(java,简单,大数)

    题目 java做大数的题,真的是神器,来一道,秒一道~~~ import java.io.*; import java.util.*; import java.math.*; public class ...

随机推荐

  1. 树莓派设置成无线路由(AP)

    1.安装需要的包 sudo apt-get install hostpad uhdcpd 2.配置/etc/network/interfaces文件 配置wlan0为静态地址 格式如下: iface ...

  2. 算法分析-堆排序 HeapSort 优先级队列

    堆排序的是集合了插入排序的单数组操作,又有归并排序的时间复杂度,完美的结合了2者的优点. 堆的定义 n个元素的序列{k1,k2,…,kn}当且仅当满足下列关系之一时,称之为堆. 情形1:ki < ...

  3. jquery.post方法回调函数

    1 function(data){} 此post请求成功后调用之,data是请求成功后服务器返回的东西.如果在servlet中有response.getWriter().println("s ...

  4. Windows 7安装教程(详细图解)

    早前向大家介绍了Windows XP的安装教程,今天思齐再来介绍一下Windows 7的安装教程,Windows 7在安装上相对以前的Windows操作系统都要简单一些,这一点对于尤其是非专业用户来说 ...

  5. Compiling Qt 5.5.1 (With Qtwebkit) With Visual Studio 2015

    I usually avoid writing articles about building a specific version of a software project but this ti ...

  6. docker 数据管理<1>

    1. 挂载本地的目录到容器里: docker run -itd -v /data/:/data1 centos bash // -v 用来指定挂载目录, :前面的/data为本地目录,:后面的/dat ...

  7. poj3085

    #include <stdio.h> #include <stdlib.h> int main() { ; scanf("%d",&n); whil ...

  8. JAVA之数组查询binarySearch()方法详解

    binarySearch()方法提供了多种重载形式,用于满足各种类型数组的查找需要,binarySearch()有两种参数类型 注:此法为二分搜索法,故查询前需要用sort()方法将数组排序,如果数组 ...

  9. magento中取不同store中的产品数据

    $products = Mage::getResourceModel('catalog/product_collection')                    ->setStoreId( ...

  10. js的this几种用法

    1.普通的函数调用 此时指的是全局对象 function aaa(){ this.x=1;}aaa();alert(x) 2.对象内的方法this调用 此时指的是上一级对象 var aaa={ zz: ...