• 跳台阶


    跳台阶

    题目:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法

    package sort;

    import java.util.Scanner;

    /**
     * @author WangXiaoeZhe
     * @Date: Created in 2019/11/22 12:43
     * @description:
     */

    public class TaiJieSort {
        public static void main(String[] args{
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            System.out.println(f(n));
        }

        /**
         * 递归方式
         */

        private static int jumpFloor(int n{
            if (n <= 1) {
                return 0;
            }
            if (n <= 2) {
                return n;
            }
            return jumpFloor(n - 1) + jumpFloor(n - 2);
        }

        /**
         * 动态规划
         */

        public static int f(int n{
            if (n <= 0) {
                return 0;
            }
            int f = 1;
            int g = 1;
            while (n-- > 0) {
                g = g + f;
                f = g - f;
            }
            return f;
        }

        /**
         * 变态跳台阶问题(可以跳任何阶)
         */

        public static int F(int n{
            if (n < 0) {
                return 0;
            }
            if (n == 1) {
                return 1;
            }
            int f = 1;
            for (int i = 0; i <= n; i++) {
                f = 2 * f;
            }
            return f;
        }

    }
  • 相关阅读:
    硅谷独角兽公司的监控系统长啥样?
    通过jQuery设置全局Ajax加载时呈现Loading
    Jquery遮罩插件,想罩哪就罩哪!
    jquery 读取textarea内容
    easy ui layout 高度 宽度自适应浏览器
    css调节样式
    ORACLE数据库的连接
    spring cloud API网关
    嵌套查询与连接查询的性能
    对于where 1=1 这种条件传入需要'%s'
  • 原文地址:https://www.cnblogs.com/wuhen8866/p/11910944.html
Copyright © 2020-2023  润新知