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;
}
'알고리즘 > 알고리즘' 카테고리의 다른 글
[C++] 프로그래머스 : 코딩테스트연습_힙 (0) | 2022.02.15 |
---|---|
[C++] 프로그래머스 : 코딩테스트연습_스택/큐 (0) | 2022.02.10 |
[C++] 프로그래머스 : 전화번호 목록 (0) | 2022.01.03 |
[C++] 프로그래머스 : 완주하지 못한 선수 (0) | 2022.01.03 |
[C++] 백준 20058번 : 마법사 상어와 파이어스톰 (0) | 2021.10.09 |