본문 바로가기

컴퓨터/코테

삼성 기출 9660 번호 붙이기

"""
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXCjuQl6J5UDFAX0&categoryId=AXCjuQl6J5UDFAX0&categoryType=CODE
"""

def dfs(lenArr, arr, idx, tmp, cnt):
    if len(tmp) == lenArr: return 1
    for next in list(filter(lambda x : x != -1 ,[i if str(i) != arr[idx] and str(i) not in tmp else -1 for i in range(1, len(arr)+1)])): cnt += dfs(lenArr, arr, idx + 1, tmp + str(next), 0)
    return cnt
for i in range(int(input())): print(dfs(int(input()), list(input().split()), 0, '', 0))

숏코딩으로 재미삼아 풀어봤다. 난이도는 D6이라 무난했다

 

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXCjuQl6J5UDFAX0&categoryId=AXCjuQl6J5UDFAX0&categoryType=CODE

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

'컴퓨터 > 코테' 카테고리의 다른 글