Xiao Ming bought a box of eggs, assuming that there are n, can eat one day, you can also eat two a day I ask how many ways you can eat?

Xiao Ming bought a box of eggs, assuming that there are n, can eat one day, you can also eat two a day I ask how many ways you can eat?

Directly on the code:

package com.shopping.test;

public class test {

    public static long getStepNumber(int n)  {
        if (0 > n) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 2;
        }
        if (n > 2) {
            return getStepNumber(n - 1) + getStepNumber(n - 2);
        }
        return 0;
    }
    public static void main(String[] args) {
        System.out.println(getStepNumber(20));
    }
}

Dynamic Programming

Guess you like

Origin www.cnblogs.com/wyf-love-dch/p/11347803.html