zoukankan      html  css  js  c++  java
  • 82. 猴子爬山

    题目描述

    一天一只顽猴想去从山脚爬到山顶,途中经过一个有个N个台阶的阶梯,但是这猴子有一个习惯: 每一次只能跳1步或跳3步,试问猴子通过这个阶梯有多少种不同的跳跃方式?

    解答要求时间限制:1000ms, 内存限制:100MB
    输入

    输入只有一个整数N(0<N<=50)此阶梯有多少个阶梯

    输出

    输出有多少种跳跃方式(解决方案数)

    样例

    输入样例 1 复制

    3
    50

    输出样例 1

    2
    122106097
    提示样例 1
     


    提示
    思路:动态规划,数组,递归
     
    代码:
    // we have defined the necessary header files here for this problem.
    // If additional header files are needed in your program, please import here.
    
    int main()
    {
        int A[55] = {0};
        int N;
        A[1] = 1;
        A[2] = 1;
        A[3] = 2;
        for(int i = 4;i<51;i++)
        {
            A[i] = A[i-1]+A[i-3];
        }
        while(scanf("%d",&N)!=EOF)
        {
            printf("%d
    ",A[N]);
        }
        // please define the C input here. For example: int n; scanf("%d",&n);
        // please finish the function body here. 
        // please define the C output here. For example: printf("%d
    ",a);    
        return 0;
    }
     
     
    以大多数人努力程度之低,根本轮不到去拼天赋~
  • 相关阅读:
    华为面试
    多线程下的单例模式
    乐观锁的一种实现方式——CAS
    乐观锁和悲观锁
    数据库行锁,表锁
    常用的设计模式
    grunt-contrib-watch 实时监测文件状态
    grunt-contrib-compass 编译sass
    grunt的安装及使用
    dede 调取二级三级菜单栏目
  • 原文地址:https://www.cnblogs.com/gcter/p/15469023.html
Copyright © 2011-2022 走看看