Data structure & Algorithm
  • Initial page
  • 1212
  • 121231
  • 2.algorithm
    • 2.1.backtracking
      • 2.1.1.連續序列的排列組合(可能會重複)
      • 2.1.3.一串數列中任取n個數字, 總共有幾種組合
      • 2.1.2.一串數列中取n個數字, 共有幾種組合
    • 2.5.Quick sort
    • 2.6.2.6.廣度優先搜尋 (Breadth-first Search)
    • 2.2.Binary Search
    • 2.1.Backtracking
    • 2.4.河內塔 (Tower of Hanoi)
    • 2.7.動態規劃
    • 2.8.深度優先搜尋 (Depth-first Search)
    • 2.7.二分搜尋法
    • 2.3.分治法 (Divide and Conquer)
  • 2.Count and Say
  • 1.Leetcode Algorithm Practice
  • 2-count-and-say
    • c-solution
    • javascript-solution
  • Algorithm
  • 123
Powered by GitBook
On this page

Was this helpful?

  1. 2.algorithm

2.1.Backtracking

Previous2.2.Binary SearchNext2.4.河內塔 (Tower of Hanoi)

Last updated 5 years ago

Was this helpful?

  • 1.Introduction (參考自:)

    • 中文稱作回溯法

    • 運用遞迴依序窮舉各個維度的數值, 製作所有可能的多維度數值, 並且在遞迴途中避免枚舉出不正確的多維度數值

  • 2.解析

    • 當num改成字串的"ABC", Recursive tree可以表示如下(圖片來源: )

    • Backtracking的架構 (參考自:)

        void backtracking()
        {
            if (填完所有空格) {
                輸出解答;
                return;
            }
            for (int i = 1; i <= 9; ++i) {
                if (i符合規則) {
                    將i填入空格;
                    backtracking(); // 遞迴下去填下個空格
                    將i從空格移除;
                }
            }
        }
http://www.eandbsoftware.org/print-all-permutations-of-a-given-string/
http://programming-study-notes.blogspot.tw/2014/03/backtracking.html