Skip to content

Commit 7b838b5

Browse files
authored
[20251006] BOJ / G5 / 팀원 모집 / 이종환
1 parent e197807 commit 7b838b5

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
```java
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.*;
7+
8+
public class Main {
9+
10+
static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
11+
static int problemCnt, studentCnt;
12+
static int goal,ans = -1;
13+
static int[] arr,comb;
14+
15+
16+
public static void main(String[] args) throws NumberFormatException, IOException {
17+
init();
18+
process();
19+
print();
20+
21+
}
22+
23+
24+
25+
public static void init() throws NumberFormatException, IOException {
26+
StringTokenizer st = new StringTokenizer(br.readLine());
27+
problemCnt = Integer.parseInt(st.nextToken());
28+
studentCnt = Integer.parseInt(st.nextToken());
29+
arr = new int[studentCnt];
30+
comb = new int[studentCnt];
31+
32+
goal = ( 1 << problemCnt)-1;
33+
34+
for (int i = 0; i < studentCnt; i++) {
35+
st = new StringTokenizer(br.readLine());
36+
int num = 0 ;
37+
int numCnt = Integer.parseInt(st.nextToken());
38+
for (int j = 0 ; j < numCnt; j++) {
39+
num += (1 << (Integer.parseInt(st.nextToken())-1));
40+
}
41+
arr[i] = num;
42+
}
43+
}
44+
45+
public static void process() throws IOException {
46+
for (int size = 1; size <= studentCnt; size++) {
47+
combination(size, 0,0);
48+
49+
if (ans == size) return;
50+
}
51+
}
52+
53+
public static void combination(int size, int idx, int cnt) {
54+
if (size == cnt) {
55+
int res = 0;
56+
57+
for (int i = 0; i < size; i++) {
58+
res |= comb[i];
59+
}
60+
if (res == goal) {
61+
ans = size;
62+
}
63+
return;
64+
}
65+
66+
for (int i = idx; i < studentCnt; i++) {
67+
comb[cnt] = arr[i];
68+
combination(size,i+1,cnt+1);
69+
}
70+
}
71+
72+
73+
74+
75+
public static void print() {
76+
System.out.print(ans);
77+
78+
}
79+
}
80+
```

0 commit comments

Comments
 (0)