返回题解分享
讨论 / 题解分享/ 帖子详情

李白打酒(结果填空) - 题解

static Set<String> ans = new HashSet<>();

    public static void main(String[] args) throws IOException {
        solution("", 2, 0, 0);
        System.out.println(ans.size());
    }

    static void solution(String path, int booze, int store, int flower) {
        if (booze == 0 && flower == 10 && store ==5) {
            ans.add(path);
        } else if (booze <= 0 || flower > 10 || store > 5) {
        } else {
            solution(path + "b", booze - 1, store, flower + 1);
            solution(path + "a", booze * 2, store + 1, flower);
        } 
    }
0 回复 0 转发 0 喜欢 5 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!