[C++][백준 9375] 패션왕 신해빈

PublicMinsu·2024년 8월 1일

문제

접근 방법

한 종류의 의상에서 입을 수 있는 경우는 의상의 개수 + 1이다. 왜냐하면 안 입는 경우도 존재하기 때문이다.

코드

#include <iostream>
#include <map>
using namespace std;
int tc, n, answer;
string name, type;
map<string, int> m;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);

    cin >> tc;

    while (tc--)
    {
        m.clear();

        cin >> n;

        while (n--)
        {
            cin >> name >> type;

            ++m[type];
        }

        answer = 1;

        for (pair<string, int> p : m)
        {
            answer *= p.second + 1;
        }

        cout << answer - 1 << "\n";
    }
    return 0;
}

풀이

각 종류에 속하는 의상의 개수 안 입는 경우를 더 하여 곱하면 된다.
하지만 아예 아무것도 안 입는 경우는 허용되지 않기에 1을 빼준다.

profile
연락 : publicminsu@naver.com

0개의 댓글