Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- 동적계획법
- 알고리즘
- 코딩테스트
- Median of Medians
- 백준
- 삽입정렬
- 프로그래밍언어
- 계수정렬
- 정수론
- 자바
- SNS
- 백트래킹
- 힙정렬
- 재귀
- java
- 자료구조
- 안드로이드
- 병합정렬
- 선택알고리즘
- DP
- 수학
- 정렬
- C++
- 기수정렬
- 퀵정렬
- 동적프로그래밍
- 버블정렬
- 프로그래밍
- 다이나믹프로그래밍
- 선택정렬
Archives
- Today
- Total
MODE::CREATIVE
[백준][c++] 9375번: 패션왕 신해빈 본문
https://www.acmicpc.net/problem/9375
문제 해석
- map 자료구조를 이용하여 옷을 입는 경우의 수 구하기
알고리즘 분류
- 수학
- 해시맵
- 조합론
풀이
- map을 이용해 (카테고리:해당 카테고리의 옷 개수)를 입력
- 계산식(sum *= it->second + 1;)을 이용해 경우의 수 출력
코드
#include <iostream>
#include <string>
#include <map>
using namespace std;
static map<string, int> mp;
void solution() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string clothes;
string catg;
cin >> clothes >> catg;
if (mp.find(catg) == mp.end()) {
mp[catg] = 1;
} else {
mp[catg]++;
}
}
long long sum = 1;
for (auto it = mp.begin(); it != mp.end(); ++it) {
sum *= it->second + 1;
}
cout << sum - 1 << endl;
mp.clear();
}
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) solution();
}'BOJ' 카테고리의 다른 글
| [백준][c++] 2606번: 바이러스 (2) | 2024.09.22 |
|---|---|
| [백준][c++] 9095번: 1, 2, 3 더하기 (0) | 2024.09.17 |
| [백준][c++] 9461번: 파도반 수열 (0) | 2024.09.14 |
| [백준][c++] 11478번: 서로 다른 부분 문자열의 개수 (0) | 2024.09.14 |
| [백준][c++] 11659번: 구간 합 구하기 4 (2) | 2024.09.09 |