Coding Problem/백준

[백준] 9375 - 패션왕 신해빈

마탁이 2021. 5. 31. 20:01

https://www.acmicpc.net/problem/9375

 

9375번: 패션왕 신해빈

첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로   (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.

www.acmicpc.net

  • 조합을 활용할 수 있어야 한다.
  • 머리에 모자하나만 얹어놔도 된다.
  • 각 옷의 type마다 입지 않았을 경우도 있다는 것을 고려하면 해결할 수 있다.
  • 마지막에는 다 벗었을 경우를 결과에서 차감하였다.
더보기
testCase = int(input())

for tc in range(testCase):
    N = int(input())

    clothesDict = dict()
    clothSet = set()
    for n in range(N):
        name, cloth = str(input()).split()

        if cloth in clothesDict.keys():
            temp = clothesDict.get(cloth)
            if( type(temp) == type(list()) ): temp.append(name)
            clothesDict[cloth] = temp
        else:
            temp = []
            temp.append(name)
            clothesDict[cloth] = temp
            clothSet.add(cloth)
    
    result = 0
    combiList = []
    for cloth in clothSet:
        nFact = 1
        nrFact = 1
        value = clothesDict.get(cloth).__len__()
        # 옷을 안입었을 경우까지 고려
        for v in range(1, value + 2): nFact *= v
        for v in range(1, value + 1): nrFact *= v
        combiList.append(nFact // nrFact)
        
    answer = 1
    for value in combiList: answer *= value
    print(answer - 1) # 모두 벗는건 제외

'Coding Problem > 백준' 카테고리의 다른 글

[백준] 11050 - 이항계수2  (0) 2021.06.01
[백준] 2004 - 조합 0의 개수  (0) 2021.06.01
[백준] 5086 - 배수와 약수  (0) 2021.05.31
[백준] 3036 - 링  (0) 2021.05.31
[백준] 1676 - 팩토리얼 0의 개수  (0) 2021.05.31