코딩테스트

[python] 백준 9375 : 패션왕 신해빈 (실버 3)

Alpaca_data_cloud 2024. 7. 22. 11:56

https://www.acmicpc.net/problem/9375

입력이 아래와 같을 때

2
3
hat headgear
sunglasses eyewear
turban headgear
3
mask face
sunglasses face
makeup face

headgear 의 경우 2개 eyewear의 경우 1개가 있다.

(2+1) * (1+1) - 1 = 5 이다. 옷을 입지 않는 경우가 있으므로 각 경우에 +1 을해주면 되고, 옷을 아예 안입으면 안되므로 -1 을 해준다.

2번째 케이스의 경우도 (3+1) - 1 = 3 이다.

test = int(input())

for t in range(test):
    n = int(input())
    cloth = dict()
    for _ in range(n):
        value , key = map(str,input().split())
        if key in cloth:
            cloth[key] += 1
        else:
            cloth[key] = 1
    result = 1
    for key in cloth:
        result *= cloth[key]+1
    print(result-1)