문제 링크

요약

  • 간단하게 생각하면 풀린다.

최종

  • 단순한 경우의수 계산이다.
    • 우선 map 에 각 type 별 몇개의 옷이 있는지를 다 세고
    • 이 옷들을 조합하는 경우의 수는 각 type 별 옷의 수를 다 곱한 값인데, 주의할 점은 해당 type 의 옷을 안입을 수도 있으니까 각 type 별 (옷의 수 + 1) 를 다 곱한 값이 전체 경우의 수이다.
    • 마지막으로 옷을 하나는 입어야 하는데 위처럼 다 곱해버리면 아무것도 안입는 경우의 수도 포함되므로, 최종 값에서 1을 빼주면 정답이 된다.
#include <string>
#include <vector>
#include <map>
 
#define CLOTH_TYPE 1
 
using namespace std;
 
int solution(vector<vector<string>> clothes) {
	map<string, int> organized;
	int ret = 1;
 
	for (auto &cloth : clothes) {
		auto &type = cloth[CLOTH_TYPE];
 
		if (organized.find(type) == organized.end()) {
			organized[type] = 1;
		} else {
			organized[type]++;
		}
	}
 
	for (auto &p : organized) {
		ret *= (p.second + 1);
	}
 
	return ret - 1;
}