// java publicvoiddivide_conquer(problem, param1, param2, ...){ // 1 recursion terminator 终止条件 if problem is None: // print_result return // 2 prepare data 处理当前层逻辑 data = prepare_data(problem); subproblems = split_problem(problem, data); // 3 conquer subproblems 调用函数下探到下一层,解决更细节的子问题 subresult1 = divide_conquer(subproblems[0], p1, ...); subresult2 = divide_conquer(subproblems[1], p1, ...); subresult3 = divide_conquer(subproblems[2], p1, ...); ... // 4 process and generate the final result result = process_result(subresult1, subresult2, subresult3, ...) // 5 revert the current level states if needed } // the difference between normal recursion and Divide&Conquer is adding one step - merge and return sub-results between drill down and revert state // 与泛型递归不同就是在drill down与revert state中间加了一步 // 就是把drill down得到的子结果要合并在一起,返回回去。