一个人上楼,他有两种走法,走一阶或走两阶,问他上 30 阶楼梯有几种走法?

作者: tihaiku 人气: - 评论: 0
问题 一个人上楼,他有两种走法,走一阶或走两阶,问他上 30 阶楼梯有几种走法?
选项
答案 1346269
解析 解析:设上 n 级楼梯的走法为 a(n),则 a(n)的值等于是 a(n-1)的值与 a(n-2)的值的和,比如上 5 级楼梯的走法是 4 级楼梯走法和 3 级楼梯走法的和,因为走 3 到级时再走一次(2 级)就到 5 级了,同样,走到 4 级时再走一级也到 5 级了。从而 a(n)=a(n-1)+a(n-2),是 斐波纳契数列。显然 1 阶楼梯 1 种走法,a(1)=1,2 阶楼梯 2 种走法,a(2)=2,所以 a(3)=1+2=3,a(4)=2+3=5,a(5)=3+5=8,...,a(30)=1346269.所以 1346269 即为所求。

猜你喜欢

更多 网友评论0 条评论)
暂无评论
错误啦!

错误信息

  • 消息: [程序异常] : MISCONF Redis is configured to save RDB snapshots, but it's currently unable to persist to disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
  • 文件: /twcms/kongphp/cache/cache_redis.class.php
  • 位置: 第 85 行
    <?php echo 'KongPHP, Road to Jane.'; ?>