본문 바로가기
  • 안녕하세요,,, 안녕히가세요,,,,
프로그램/코딩테스트

삼성 Expert 1244 최대 상금

by 차보루타 2022. 6. 13.
ans = 0
 
 
def dfs(count):
    global ans
 
    temp = int(''.join(ar))
 
    if count == 0:
        ans = max(ans, temp)
 
        return
 
    for i in range(len(ar)):
        for j in range(i + 1, len(ar)):
            ar[i], ar[j] = ar[j], ar[i]
 
            temp_key = ''.join(ar)
 
            if chk.get((temp_key, count - 1), 1):
                chk[(temp_key, count - 1)] = 0
                dfs(count - 1)
 
            ar[i], ar[j] = ar[j], ar[i]
 
 
for test_case in range(1, int(input()) + 1):
    ans = 0
 
    ar, n = input().split()
    ar = list(ar)
    n = int(n)
 
    chk = {}
 
    dfs(n)
 
    print(f'#{test_case} {ans}')

'프로그램 > 코딩테스트' 카테고리의 다른 글

삼성 Expert 14178 1차원 정원  (0) 2022.06.13
삼성 Expert 1206 View  (0) 2022.06.13
삼성 Expert 1208 Flatten  (0) 2022.06.13
백준 7562 나이트의 이동  (0) 2022.06.13
백준 1743 음식물 피하기  (0) 2022.06.13

댓글