어제 못풀었던 거.
꿈에서 풀다가 오늘 다시 풀었다.
1. 집합의 조합은 |A|*|B| 이다.
2. 의상이 0개인 경우를 고려해 각 집합에 +1을 해주었다.
3. 하지만, 모든 집합이 0인 경우는 없기에 -1을 보정해준다.
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
unordered_map<string, int> cloType;
for (const auto& clotheVec : clothes)
{
++cloType[clotheVec[1]];
}
for (const auto& count : cloType)
{
answer *= (count.second + 1);
}
return answer - 1;
}
'학습(0) > C++ 문제풀이' 카테고리의 다른 글
문자열 정렬/ isdigit()/ reserve() (0) | 2025.03.11 |
---|---|
모음 제거/ remove_if (0) | 2025.03.11 |
메뉴 리뉴얼 /조합 익히자 (0) | 2025.03.10 |
신고 결과 받기 (0) | 2025.03.09 |
베스트 앨범 (0) | 2025.03.09 |