[問題] DFS -窮舉
看板C_and_CPP (C/C++)作者qazwsx879345 (Rajon Rondo)時間7年前 (2018/08/07 00:35)推噓1(1推 0噓 7→)留言8則, 1人參與討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...)
Win 10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
c++
問題(Question):
想要使用dfs 來窮舉排列組合
但因為之後會加入一些函式判斷
可能再某一層就不繼續嘗試
ex: 0 1 2 3
到0 1 就判斷不可能繼續執行 就不繼續作了
--
因此資料量大
不想使用#include<algorithm>
裡面的next_permutation
那種窮舉的寫法
ex:https://blog.csdn.net/liuxingbusi/article/details/53556564
餵入的資料(Input):
(0,1,2)
預期的正確結果(Expected Output):
(0,1,2)
(0,2,1)
(1,0,2)
(1,2,0)
(2,1,0)
(2,0,1)
錯誤結果(Wrong Output):
compile error
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
https://ideone.com/zEv3pe
補充說明(Supplement):
網路上查過很多方法
但都是直接cout把它印出來
ex:https://goo.gl/tq7BqV
而我是想要的是
輸入一個vector<int> ex:0,1,2
將各種可能組合存入一個vector<vector<int>>以做後續的使用
但因為前陣子使用python較多
可能對於一些函式的使用還有call by reference之類的概念有的不好QQ
卡關整晚 有點崩潰 因此上來求救QQ
想請問該怎麼寫會比較好呢QQ
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 39.8.133.181
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1533573303.A.D51.html
推
08/07 01:17,
7年前
, 1F
08/07 01:17, 1F
→
08/07 01:18,
7年前
, 2F
08/07 01:18, 2F
→
08/07 01:18,
7年前
, 3F
08/07 01:18, 3F
→
08/07 01:20,
7年前
, 4F
08/07 01:20, 4F
→
08/07 01:20,
7年前
, 5F
08/07 01:20, 5F
→
08/07 01:22,
7年前
, 6F
08/07 01:22, 6F
→
08/07 01:27,
7年前
, 7F
08/07 01:27, 7F
→
08/07 01:28,
7年前
, 8F
08/07 01:28, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章