Find that 2019 I have this draft. Now I can solve it easily.
truth is traverse the graph . if this node was met, then don’t go deeper. Sequence traverse lead to dictionary order.
use fp thought, two here to keep the var only change during recursion.
how to output odd-even sequence?
Black history
先考虑列举出所有的情况。
但是很明显,这个没有回溯的过程。用 if 判断边界来避免死循环。当深入到第 k 层,就不会深入了。等于是关掉了递归的门。
如果加了return,则在k=n+1时回溯,其实这里还多赋了一个a[k+1],只不过输出时没有输出而已。而这个多余的a[k+1],永远都是1,因为for循环的第一个i是1,然后赋完就print,就return了,没机会继续赋。
说了那么多,接着想想如何去重。
我知道了,之前自己的姿势不对。递归不用去想栈是怎么运行的。。。不然会把自己绕进去
排1个元素,没问题,排n个,假设没问题,排n+1个,就没问题了。
直接这么想,怎么去重呢?假设在排第k个数,那么排前k-1个数时,顺带把路堵死,(sign=true)
排第n个数时,就只能取没被堵死的路。
到k=n+1时,输出。完成for循环,然后return到上一层。(要出界再回来)