Skip to content

Commit 7b173ee

Browse files
author
hangyeol
committed
112차 1번 문제풀이
1 parent 8e9335d commit 7b173ee

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
3+
def main():
4+
input = sys.stdin.readline
5+
N = int(input())
6+
7+
for i in range(N):
8+
word = str(input().strip())
9+
10+
word = sorted(list(word))
11+
12+
result = []
13+
backtracking(word, [], [False] * len(word), result)
14+
15+
for r in result:
16+
print(r)
17+
18+
def backtracking(word, path, visited, result):
19+
if len(path) == len(word):
20+
result.append("".join(path))
21+
return
22+
23+
for i in range(len(word)):
24+
if visited[i]:
25+
continue
26+
if i > 0 and word[i] == word[i-1] and not visited[i-1]:
27+
continue
28+
29+
visited[i] = True
30+
path.append(word[i])
31+
backtracking(word, path, visited, result)
32+
path.pop()
33+
visited[i] = False
34+
35+
if __name__ == '__main__':
36+
main()

0 commit comments

Comments
 (0)