Programing/백준, 프로그래머스(C++)
[C++][백준 9375] 패션왕 신해빈
hye3193
2025. 1. 21. 17:35
https://www.acmicpc.net/problem/9375
풀이
가지고 있는 각 의상의 종류로 나올 수 있는 경우의 수를 구하는 문제다
map을 이용해 각 의상별로 몇 벌을 가지고 있는지 체크하고, 경우의 수를 구해주면 된다
제출 코드
#include <iostream>
#include <map>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t, n;
string input;
cin >> t;
while(t--)
{
map<string, int> m;
cin >> n;
while(n--)
{
cin >> input >> input;
m[input]++;
}
int sum = 1;
for (auto cloth : m)
sum = sum * (cloth.second + 1);
cout << --sum << '\n';
}
}
의상의 이름은 어차피 겹치지 않는다고 했으니 덮어쓰는 식으로 넘겨주었다
아무 의상도 걸치지 않는 경우의 수는 제외하고 세어야 하기 때문에 마지막에 1을 빼고 출력해 주면 된다