首页 > 其他 > 详细

李白打酒

时间:2018-05-08 00:07:18      阅读:373      评论:0      收藏:0      [点我收藏+]

李白打酒这个用暴力递归很容易算出来,今天想要加上链路记录,原本以为挺简单的事情,却想了很久才想明白,记录一下吧。

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;
    }
}

  

李白打酒

原文:https://www.cnblogs.com/sansamh/p/9005917.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!