发布时间:2023-11-17 12:30
题目:(1)一只青蛙一次可以跳上 1 级台阶,也可以跳上2 级。求该青蛙跳上一个n 级的台阶总共有多少种跳法。
分析:当n = 1, 只有1中跳法;当n = 2时,有两种跳法;当n = 3 时,有3种跳法;当n = 4时,有5种跳法;当n = 5时,有8种跳法 这个规律类似于Fibonacci数列,使用递归的思想,代码如下:
#include
#include
int jump_floor(int n)
{
if (n < 3)
{
return n;
}
else
{
return jump_floor(n - 2) + jump_floor(n - 1);
}
}
int main()
{
int n = 0;
printf(\"请输入跳的台阶数:\");
scanf_s(\"%d\", &n);
int ret=jump_floor(n);
printf(\"%d\\n\", ret);
system(\"pause\");
return 0;
}
2020李宏毅机器学习笔记-Generative Adversarial Network - Conditional GAN
TypeError The view function did not return a valid response. The function either returned None 的解决
笔记:STM32启动文件startup_stm32f10x_xx.s
[Datawhale-李宏毅机器学习-39期]-001-机器学习介绍
SpringCloud系列——构建多模块应用,远程调用服务day1-3
DatenLord|重新思考Rust Async如何实现高性能IO
MindSpore报错 Select GPU kernel op * fail! Incompatible data type