<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 在矩陣中從左上到右下打印所有回文路徑 > 原文: [https://www.geeksforgeeks.org/print-palindromic-paths-top-left-bottom-right-matrix/](https://www.geeksforgeeks.org/print-palindromic-paths-top-left-bottom-right-matrix/) 給定一個僅包含較低字母字符的矩陣,我們需要在給定的矩陣中打印所有回文路徑。 路徑定義為從左上角的單元格到右下角的單元格的一系列單元格。 我們只能從當前單元格左右移動。 我們不能斜著走。 **例如**: ``` Input : mat[][] = {"aaab”, "baaa” “abba”} Output :aaaaaa, aaaaaa, abaaba Explanation : aaaaaa (0, 0) -> (0, 1) -> (1, 1) -> (1, 2) -> (1, 3) -> (2, 3) aaaaaa (0, 0) -> (0, 1) -> (0, 2) -> (1, 2) -> (1, 3) -> (2, 3) abaaba (0, 0) -> (1, 0) -> (1, 1) -> (1, 2) -> (2, 2) -> (2, 3) ``` 輸出數組中元素的順序無關緊要。 這個想法很簡單。 我們從左上角(0,0)開始,探索到右下角的所有路徑。 如果路徑變成回文,我們將其打印出來。 ## C++ ```cpp // C++ program to print all palindromic paths // from top left to bottom right in a grid. #include<bits/stdc++.h> using namespace std; #define N 4 bool isPalin(string str) { ????int len = str.length() / 2; ????for (int i = 0; i < len; i++)? ????{ ????????if (str[i] != str[str.length() - i - 1]) ????????????return false; ????} ????return true; } // i and j are row and column indexes of current cell? // (initially these are 0 and 0). void palindromicPath(string str, char a[][N], ????????????????????????????int i, int j, int m, int n) { ????// If we have not reached bottom right corner, keep ????// exlporing ????if (j < m - 1 || i < n - 1)? ????{ ????????if (i < n - 1) ????????????palindromicPath(str + a[i][j], a, i + 1, j, m, n); ????????if (j < m - 1) ????????????palindromicPath(str + a[i][j], a, i, j + 1, m, n); ????}? ????// If we reach bottom right corner, we check if ????// if the path used is palindrome or not. ????else { ????????str = str + a[n - 1][m - 1]; ????????if (isPalin(str)) ????????????cout<<(str)<<endl; ????} } // Driver code? int main() { ????char arr[][N] = { { 'a', 'a', 'a', 'b' }, ????????????????????{ 'b', 'a', 'a', 'a' }, ????????????????????{ 'a', 'b', 'b', 'a' } }; ????string str = ""; ????palindromicPath(str, arr, 0, 0, 4, 3); ????return 0; } // This code is contributed by andrew1234 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看