HDU 1250 Hat's Fibonacci
来源:互联网 发布:淘宝店推广引流的技巧 编辑:程序博客网 时间:2024/06/06 11:47
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
题目大意:
数组F中,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),输入一个数n让你输出F[n]
#include <iostream>#include<cstring>#include<cstdio>using namespace std;int a[7500][600];int main(){ int b,c,d,e,f,j,g; memset(a,0,sizeof(a)); a[0][0]=1;a[1][0]=1;a[2][0]=1;a[3][0]=1; f=0;g=0; for(b=4;b<7500;b++) { for(j=0;j<=g;j++) { a[b][j]=a[b-1][j]+a[b-2][j]+a[b-3][j]+a[b-4][j]; } for(j=0;j<=g;j++) //a数组中数值>=10000时进位 { a[b][j+1]+=a[b][j]/10000; a[b][j]%=10000; } if(a[b][g]) { g++; } } while(cin>>e) { for(f=g;f>=0;f--) //判断直到数组a中数不为0时输出 { if(a[e-1][f]!=0) break; } cout<<a[e-1][f]; f--; for(;f>=0;f--) { printf("%04d",a[e-1][f]); } cout<<endl; } return 0;}
阅读全文
0 0
- hdu 1250 Hat's Fibonacci
- HDU 1250 Hat's Fibonacci
- Hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- HDU 1250-Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu-1250-Hat's Fibonacci
- Hdu---Hat's Fibonacci---1250
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- HDU 1250: Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu 1250 Hat's Fibonacci
- hdu-1250-Hat's Fibonacci
- HDU 1250 Hat's Fibonacci
- HDU 1250 Hat's Fibonacci
- Android在AutoCompleteTextView中输入字母或者汉字通过Filterable实现自动筛选提醒
- Centos setup opencv
- C语言预处理和函数
- 【数据结构】最大堆的插入与删除
- JQuery 取dom集合 name属性为数组时
- HDU 1250 Hat's Fibonacci
- ubuntu安装tftp
- Largest Rectangle in a Histogram
- 【Bzoj1060】时态同步
- windows 下 sourceTree 乱码问题
- Android碎片Fragment的点击切换
- 和为S的连续正数序列(java版)
- POJ 1313 Booklet Printing 笔记
- 直接插入排序与希尔排序