Li Bai hits wine

It is easy to calculate Li Bai's drinking by violent recursion. I wanted to add a link record today. I thought it was a simple matter, but it took me a long time to figure it out. Let's record it.

public class LibaiDajiu2 {

    static char[] c = new char[15];
    static int sum = 0;
    public static void main(String[] args) {

        System.out.println(fun(5,10,2,0));
    }

    private static int fun(int d  , int h, int count, int step) {
        if( d ==0 && h ==1 && count == 1 ){
            sum ++;
        }
        if(d> 0){
            fun(d-1,h,count*2,step+1);
        }
        if(h>0){
            fun(d,h-1,count-1,step+1);
        }
        return sum;
    }
}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325693172&siteId=291194637