본문 바로가기
알고리즘/알고리즘

[C++] 프로그래머스 : 위장

by 두둠칫 2022. 1. 4.

1. 해시 풀이

적어도 하나의 부위를 입는 각 부위별 가짓수의 조합은

(a+1)*(b+1)* ... * (c+1) - 1(아예 안입는경우)

#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

int solution(vector<vector<string>> clothes) {
    int answer = 1;
    
    unordered_map<string, int> m;
    for(vector<string> c : clothes){
        m[c[1]]++;
    }
    
    for(auto a : m){
        answer*=(a.second+1);
    }
    
    if(answer == 1) answer = 0;
    else answer--;
    
    return answer;
}