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)로 계산
- 모든 종류의 경우의 수를 곱하고, 아무것도 입지 않는 경우를 제외하여 최종 결과를 구한다.
'Algorithm > 백준' 카테고리의 다른 글
항해99 리부트코스 알고리즘 2주 3일차 백준 1026 보물 (0) | 2024.07.26 |
---|---|
백준 코딩테스트 1202 보석 도둑 (0) | 2024.07.25 |
항해99 리부트코스 알고리즘 2주 2일차 백준 14235 크리스마스 선물 (0) | 2024.07.25 |
항해99 리부트코스 알고리즘 2주 2일차 백준 1927 최소 힙 (0) | 2024.07.25 |
항해99 리부트코스 알고리즘 2주 2일차 백준 19638 센티와 마법의 뿅망치 (0) | 2024.07.25 |