sgu 123 The sum
来源:互联网 发布:2016年度网络十大歌曲 编辑:程序博客网 时间:2024/05/07 21:46
题目描述:
123. The sum
time limit per test: 0.5 sec.
memory limit per test: 4096 KB
The Fibonacci sequence of numbers is known: F1 = 1; F2 = 1; Fn+1 = Fn + Fn-1, for n>1.You have to find S - the sum of the first K Fibonacci numbers.
Input
First line contains natural number K(0<K<41).
Output
First line should contain number S.
Sample Input
5
Sample Output
12
告诉你K,求前K个Fibonacci数的和。预处理一下或直接暴搞就可以,属于水题。
代码:
#include<iostream>#include<cstring>#include<cstdio>#include<set>#include<algorithm>#include<vector>#include<cstdlib>#define inf 0xfffffff#define CLR(a,b) memset((a),(b),sizeof((a)))using namespace std;int const nMax = 50;typedef long long LL;typedef pair<LL,LL> pij;LL Fi[nMax];LL sum[nMax];int main(){ Fi[0]=0,Fi[1]=1; for(int i=2;i<nMax;i++)Fi[i]=Fi[i-1]+Fi[i-2]; sum[0]=0; for(int i=1;i<nMax;i++){ sum[i]=sum[i-1]+Fi[i]; } int n; while(cin>>n){ cout<<sum[n]<<endl; } return 0;}
- sgu 123 The sum
- sgu 123 The sum
- SGU - 123 - The sum (简单数学!)
- SGU 123 The sum(水~)
- [SGU]123. The sum
- Sgu 123. The sum
- SGU 123. The sum 无敌水题
- SGU:231 Prime Sum
- sgu 106 The equation
- SGU 106 The equation
- [SGU]106. The Equation
- sgu 106 The equation
- [SGU]122. The book
- sgu 122 The book
- sgu 146 The Runner
- sgu 186 The Chain
- SGU 106 The euqation
- sgu 146 The Runner
- C# WebClient UploadFile测试通过
- 一个SQLServer通用分页查询过程
- 隆重推荐【SQLServer】127个SQL server热门资料汇总
- 如何高效阅读源码
- 封装过的Ajax工具类库
- sgu 123 The sum
- 简单易用美观的日期及时间控件
- [cocos2d-x 学习] Windows下环境配置
- 来自亚马逊总裁Jeff Bezos的一些建议
- 批处理(bat)命令大全
- C#调用webservice
- 使用回溯法求解数独问题,数独游戏算法
- java代码优化方案(转)
- 关于ruby的new方法的一点思考