From 7b838b56782a2ad9b0a7d4fb2729b81f8f6f4d26 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 6 Oct 2025 16:54:27 +0900 Subject: [PATCH] =?UTF-8?q?[20251006]=20BOJ=20/=20G5=20/=20=ED=8C=80?= =?UTF-8?q?=EC=9B=90=20=EB=AA=A8=EC=A7=91=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \354\235\264\354\242\205\355\231\230.md" | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 "0224LJH/202510/06 \355\214\200\354\233\220\353\252\250\354\247\221 \354\235\264\354\242\205\355\231\230.md" diff --git "a/0224LJH/202510/06 \355\214\200\354\233\220\353\252\250\354\247\221 \354\235\264\354\242\205\355\231\230.md" "b/0224LJH/202510/06 \355\214\200\354\233\220\353\252\250\354\247\221 \354\235\264\354\242\205\355\231\230.md" new file mode 100644 index 00000000..e5f83fae --- /dev/null +++ "b/0224LJH/202510/06 \355\214\200\354\233\220\353\252\250\354\247\221 \354\235\264\354\242\205\355\231\230.md" @@ -0,0 +1,80 @@ +```java + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + + static BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); + static int problemCnt, studentCnt; + static int goal,ans = -1; + static int[] arr,comb; + + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + + } + + + + public static void init() throws NumberFormatException, IOException { + StringTokenizer st = new StringTokenizer(br.readLine()); + problemCnt = Integer.parseInt(st.nextToken()); + studentCnt = Integer.parseInt(st.nextToken()); + arr = new int[studentCnt]; + comb = new int[studentCnt]; + + goal = ( 1 << problemCnt)-1; + + for (int i = 0; i < studentCnt; i++) { + st = new StringTokenizer(br.readLine()); + int num = 0 ; + int numCnt = Integer.parseInt(st.nextToken()); + for (int j = 0 ; j < numCnt; j++) { + num += (1 << (Integer.parseInt(st.nextToken())-1)); + } + arr[i] = num; + } + } + + public static void process() throws IOException { + for (int size = 1; size <= studentCnt; size++) { + combination(size, 0,0); + + if (ans == size) return; + } + } + + public static void combination(int size, int idx, int cnt) { + if (size == cnt) { + int res = 0; + + for (int i = 0; i < size; i++) { + res |= comb[i]; + } + if (res == goal) { + ans = size; + } + return; + } + + for (int i = idx; i < studentCnt; i++) { + comb[cnt] = arr[i]; + combination(size,i+1,cnt+1); + } + } + + + + + public static void print() { + System.out.print(ans); + + } +} +```