Algorithm/BOJ
[BOJ] 패션왕 신해빈
goakgoak
2020. 5. 27. 14:51
[9575] 패션왕 신해빈
https://www.acmicpc.net/problem/9375
- 해빈이가 가진 옷들로 만들 수 있는 모든 조합의 수 구하기
Solution
- 해빈이가 가진 의상의 이름과 종류가 공백으로 주어지면 의상의 종류와 count를 HashMap에 저장한다.
- answer = (의상종류1 + 안 입는 경우) * (의상종류2 + 안 입는 경우) * (...) * (의상종류n + 안 입는 경우) - 다 안 입는 경우
- answer *= ( map.get(key) +1 ); answer -= 1;
소스코드
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
32
33
34
35
36
37
38
39
40
41
42
|
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
static int tc, answer;
static HashMap<String, Integer> map;
static StringTokenizer st;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
tc = sc.nextInt();
while (tc-- > 0) {
answer = sc.nextInt();
sc.nextLine();
init();
for (int i = 0; i < answer; i++) {
st = new StringTokenizer(sc.nextLine());
st.nextToken();
String item = st.nextToken();
if (map.containsKey(item)) {
map.replace(item, map.get(item) + 1);
} else {
map.put(item, 1);
}
}
answer = 1;
for (String key : map.keySet()) {
answer *= (map.get(key) + 1);
}
answer -= 1;
System.out.println(answer);
}
}
public static void init() {
map = new HashMap<>();
}
}
|
cs |