https://www.acmicpc.net/problem/9375
import sys
input = sys.stdin.readline
N = int(input().rstrip())
for _ in range(N):
M = int(input().rstrip())
clothes = {}
for _ in range(M):
(item, cloth_type) = list(input().rstrip().split())
clothes[cloth_type] = clothes.get(cloth_type, 0) + 1
result = 1
for count in clothes.values():
result *= (count + 1) #해당 종류의 의상을 선택하지 않는 경우 포함
print(result - 1) # 아무 옷도 안 입는 경우 제외
의상 타입별 고르지 않는 경우도 카운트하는게 중요하다.
반응형
'알고리즘 문제풀기 > 백준 - Python' 카테고리의 다른 글
[백준 11478] 서로 다른 부분 문자열의 개수 - Python (해시맵) (0) | 2025.03.13 |
---|---|
[백준 1158] 요세푸스 문제 - Python(큐, 링크드 리스트) (0) | 2025.03.11 |
[백준 3015] 오아시스 재결합 - Python(스택) (0) | 2025.03.09 |
[백준 6198] 옥상 정원 꾸미기 - Python(스택) (0) | 2025.03.06 |
[백준 2493] 탑 - Python(스택) (0) | 2025.03.06 |