[백준] #9375 패션왕 신해빈 python

2023. 1. 3. 16:32

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

 

9375번: 패션왕 신해빈

첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로   (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.

www.acmicpc.net

 

📕 설명 📕

경우의 수를 활용하여,

 

(종류의 수 + 1) * (종류의 수 + 1) * ... - 1

로 계산한다.

 

한 가지 빼는 경우는 알몸인 경우이다.

🧑🏻‍💻 나의 풀이 🧑🏻‍💻

from collections import Counter
T = int(input())

for _ in range(T):
    N = int(input())
    N_dict = {}
    for i in range(N):
        cloth, kinds = map(str,input().split())
        if kinds not in N_dict:
            N_dict[kinds] = [cloth]
        else:
            N_dict[kinds].append(cloth)
    result = 1
    for i in N_dict:
        result *= len(N_dict[i]) + 1
    print(result - 1)

 

 

BELATED ARTICLES

more