DFS for permutations