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)
'코딩테스트' 카테고리의 다른 글
[python] 백준 17626 : Four Squares (실버 3) (2) | 2024.07.24 |
---|---|
[python] 백준 9461 번 : 파도반 수열 (실버 3) (2) | 2024.07.23 |
[python] 1389 번 : 케빈 베이컨의 6단계 법칙 (실버 1) (0) | 2024.07.19 |
[python] 백준 2579 : 계단 오르기 (실버 3) (0) | 2024.07.18 |
[python] 백준 7569 : 토마토 (골드 5) (0) | 2024.07.17 |