Home (Python)[백준] 패션왕 신해빈
Post
Cancel

(Python)[백준] 패션왕 신해빈

9375번: 패션왕 신해빈

문제 풀이


알몸으로 다니지 않는 경우의 수는 (종류별 옷의 수) + 1 을 전부 곱해주고(해당 종류의 옷을 안 입는 경우의 수를 포함한 것) 알몸의 경우의 수인 1만 빼주면 된다.

소스 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
input = sys.stdin.readline

T = int(input())
for _ in range(T):
    n = int(input())
    clothes = {}
    for _ in range(n):
        _, key = input().split()
        if key in clothes:
            clothes[key] += 1
        else:
            clothes[key] = 1

    anw = 1
    if len(clothes) == 1:
        anw = clothes[key]
        print(anw)
    else:
        for i in clothes:
            anw *= (clothes[i]+1)
        print(anw-1)
This post is licensed under CC BY 4.0 by the author.