[Python] 패션왕 신해빈 [백준 9375]

のの·2021년 5월 30일

풀이

  • 해싱 문제로 딕셔너리를 이용해 문제를 해결
  • 의상의 수는 (0 ≤ n ≤ 30)이 주어진다.
  • 알몸이 아닌 상태로 의상울 입을 수 있는 경우는
    (모든 경우의 수) - (알몸인 상태) 의 경우의 수를 구하는 문제와 같다.
import sys

N = int(input())
i = 0
while i < N:
    
    n = int(input())
    wear = {}
    res = 1
    j = 0
    while j < n:
        name, category = map(str, sys.stdin.readline().split())
        if category not in wear:
            wear[category] = [name]
        else:
            wear[category].append(name)
        j += 1
    
    for category in wear.keys():
    	# 각 케이스에서 의상을 입지 않는 경우는 1가지이다.
        res *= (len(wear[category]) + 1)
    
    # 전체 경우의 수에서 알몸인 경우를 제외한 경우의 수를 출력한다.
    print(res - 1)
    # 출력을 완료 했다면 딕셔너리를 제거한다.
    del(wear)    
    i += 1
profile
wannabe developer

0개의 댓글