BOJ
[백준][c++] 9375번: 패션왕 신해빈
LEE MINGYU
2024. 9. 14. 19:26
https://www.acmicpc.net/problem/9375
문제 해석
- map 자료구조를 이용하여 옷을 입는 경우의 수 구하기
알고리즘 분류
- 수학
- 해시맵
- 조합론
풀이
- map을 이용해 (카테고리:해당 카테고리의 옷 개수)를 입력
- 계산식(sum *= it->second + 1;)을 이용해 경우의 수 출력
코드
#include <iostream>
#include <string>
#include <map>
using namespace std;
static map<string, int> mp;
void solution() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string clothes;
string catg;
cin >> clothes >> catg;
if (mp.find(catg) == mp.end()) {
mp[catg] = 1;
} else {
mp[catg]++;
}
}
long long sum = 1;
for (auto it = mp.begin(); it != mp.end(); ++it) {
sum *= it->second + 1;
}
cout << sum - 1 << endl;
mp.clear();
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) solution();
}