알고리즘

C++ 알고리즘 - 백준 9375 패션왕 신해빈

마루설아 2025. 1. 5. 23:04

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

 

#include <bits/stdc++.h>
#include <unordered_map>
#define endl "\n"

using namespace std;

int main(void) {
	/************** C++ Init **************/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/************** C++ Init **************/


	int input1, input2;
	string str1, str2;
	unordered_map<string, int> um;
	vector<string> v;
	cin >> input1;

	for (int i = 0; i < input1; i++) {
		int cnt = 1; 
		v.clear();
		um.clear();

		cin >> input2;

		for (int j = 0; j < input2; j++) {
			cin >> str1 >> str2;
			if (um[str2] == 0) {
				um.insert({ str2, 0 });
				v.push_back(str2);
			}

			um[str2]++;
		}

		for (int k = 0; k < v.size(); k++) {
			cnt *= um[v[k]] + 1;
		}

		cout << cnt - 1 << endl;
	}
}

 

모든 경우의 수 - 1 (아무것도 안 입는 경우)