Algorithm/백준

항해99 리부트코스 알고리즘 2주 2일차 백준 9375 패션왕 신해빈

Albosa2lol 2024. 7. 25. 17:03

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

 

 

풀이

 

def solve():
    import sys
    input = sys.stdin.readline

    T = int(input().strip())  # 테스트 케이스 수
    results = []

    for _ in range(T):
        n = int(input().strip())
        clothes = {}

        for _ in range(n):
            name, kind = input().strip().split()
            if kind in clothes:
                clothes[kind] += 1
            else:
                clothes[kind] = 1

        combinations = 1
        for kind in clothes:
            combinations *= (clothes[kind] + 1)  # 해당 종류의 옷을 입지 않는 경우 포함

        results.append(combinations - 1)  # 아무것도 입지 않는 경우 제외

    for result in results:
        print(result)

if __name__ == "__main__":
    solve()

 

 

  • 각 종류별 의상의 수를 센다.
  • 각 종류별로 의상을 입지 않는 경우를 포함하여 (의상의 수 + 1)로 계산
  • 모든 종류의 경우의 수를 곱하고, 아무것도 입지 않는 경우를 제외하여 최종 결과를 구한다.