백준 9375 - 패션왕 신해빈

황재진·2024년 7월 30일

백준

목록 보기
51/54

경우의 수를 구하는 간단한 문제입니다.

백준에 있는 예시처럼 heargear 2종류, eyewear 1종류가 있을 때 각 가능한 경우의 수를 아래처럼 나열할 수 있습니다.

가능한 모든 조합은 3 x 2로 6가지입니다. 하지만 입고 있는 것이 하나도 없는 경우를 제외해야 하므로 1을 뺍니다.

#include <iostream>
#include <map>

int main()
{
	int test;
	std::cin >> test;

	for (int t = 0; t < test; t++)
	{
		int cnt;
		std::cin >> cnt;

		std::map<std::string, int> wears;

		for (int i = 0; i < cnt; i++)
		{
			std::string name, type;
			std::cin >> name >> type;

			if (wears.find(type) == wears.end()) wears.insert({ type, 2 });
			else wears[type]++;
		}

		int result = 1;
		for (const auto it : wears)
			result *= it.second;
		result--;
		std::cout << result << "\n";
	}

	return 0;
}
profile
프로그래밍, 쉐이더 등 이것저것 다해보는 게임 개발자입니다

0개의 댓글