<Sicily>Fibonacci

一、题目描述

In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn-1 + Fn-2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …

Given an integer n, your goal is to compute the last Fn mod (10^9 + 7).

二、输入

The input test file will contain a single line containing n (n ≤ 100).

There are multiple test cases!

三、输出

For each test case, print the Fn mod (10^9 + 7).

例如:
输入:9
输出:34

四、解题思路

使用动态规划思想,大问题由小问题组成。
第3项可以由1,2项求得,
第4项可以由2,3项求得,

第n项可以由n - 2, n - 1求得。

五、代码

#include <iostream>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值