[백준] 9375번 파이썬

Heejun Kim·2022년 6월 20일
0

Coding Test

목록 보기
38/51

문제: https://www.acmicpc.net/problem/9375
문제 해결 방법

  1. 생각보다 간단한 조합 문제였다. 각 옷의 종류를 먼저 저장한다.
  2. 이때 해당 옷의 종류를 입지 않는 경우도 생각해 옷의 종류가 가지는 개수에 + 1을 더해준다.
  3. 이렇게 된다면 headgear의 개수 * face 개수 - 1(둘 다 입지 않았을 경우)로 답을 쉽게 구할 수 있다.
import sys
input = sys.stdin.readline

t = int(input())
for _ in range(t):
    n = int(input())
    cloths = {}
    for _ in range(n):
        cloth = list(map(str, input().split()))[-1]
        cloths[cloth] = cloths.get(cloth, 1) + 1

    answer = 1
    cloths_list = list(cloths.values())
    for i in range(len(cloths_list)):
        answer *= cloths_list[i]
    print(answer - 1)

0개의 댓글