https://www.acmicpc.net/problem/2661
import sys
def check(res):
for i in range(1, len(res)//2+1):
if res[-i*2:-i] == res[-i:]:
return True
return False
def backtracking(L, res):
global result
if check(res):
return
if L == n:
print(res)
sys.exit(0)
else:
for i in range(3):
backtracking(L+1, res+ls[i])
if __name__ == "__main__":
n = int(input())
print('n :', n)
ls = ["1", "2", "3"]
result = 0
for j in range(3):
backtracking(1, ls[j])
'Algorithm > Failed' 카테고리의 다른 글
[LeetCode][316] 스택, 재귀를 이용해 다시 풀 문제 (0) | 2023.01.13 |
---|
댓글