1. 分治

  1. public void divideConquer(int problem, int param) {
  2. // recursion terminator
  3. if (problem == null) {
  4. return;
  5. }
  6. // prepare data
  7. data = prepareDate(problem);
  8. subProblems = splitProblem(problem, data);
  9. // conquer sub problems
  10. subResult1 = divideConquer(subProblems[0], param);
  11. subResult2 = divideConquer(subProblems[1], param);
  12. subResult3 = divideConquer(subProblems[2], param);
  13. subResult4 = divideConquer(subProblems[3], param);
  14. // ...
  15. result = processResult(subResult1, subResult2, subResult3, subResult4);
  16. // revert thr current level states.
  17. }

1.1 pow(x,n) (50)

  • 解法1: 循环

  • 解法2: 分治

  • 解法3: 牛顿迭代法

2. 回溯

2.1 子集(78)

  • 解法1:

2.2 众数

2.3 电话号码的字母组合(17)

  • 解法1: 递归

  • s

2.4 N皇后问题