Skip to content

Commit 8f8c362

Browse files
committed
[D5] Title: 수제 버거 장인, Time: 204 ms, Memory: 36,536 KB -BaekjoonHub
1 parent 130e630 commit 8f8c362

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D5] 수제 버거 장인 - 3421
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWErcQmKy6kDFAXi)
4+
5+
### 성능 요약
6+
7+
메모리: 36,536 KB, 시간: 204 ms, 코드길이: 1,242 Bytes
8+
9+
### 제출 일자
10+
11+
2026-09-10 17:23
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import java.util.*;
2+
import java.io.FileInputStream;
3+
4+
5+
class Solution
6+
{
7+
public static List<int[]> list;
8+
public static int N, M;
9+
public static boolean[] selected;
10+
11+
public static int result;
12+
13+
public static void main(String args[]) throws Exception
14+
{
15+
16+
Scanner sc = new Scanner(System.in);
17+
int T;
18+
T=sc.nextInt();
19+
20+
for(int test_case = 1; test_case <= T; test_case++)
21+
{
22+
23+
N = sc.nextInt();
24+
M = sc.nextInt();
25+
26+
list = new ArrayList<>();
27+
28+
for(int i=0; i<M; i++) {
29+
int a = sc.nextInt();
30+
int b = sc.nextInt();
31+
list.add(new int[] {a, b});
32+
}
33+
// a,b가 동시에 버거에 들어가면 안된다.
34+
35+
result = 0;
36+
selected = new boolean[N+1];
37+
dfs(1);
38+
System.out.println("#" + test_case + " " + result);
39+
40+
list.clear();
41+
}
42+
43+
sc.close();
44+
}
45+
46+
public static void dfs(int idx) {
47+
if(idx > N) {
48+
result++;
49+
return;
50+
}
51+
52+
// 현재 재료를 넣지 않는 경우
53+
dfs(idx+1);
54+
55+
// 현재 재료를 넣는 경우
56+
selected[idx] = true;
57+
58+
boolean canInclude = true;
59+
for(int[] pair : list) {
60+
int a = pair[0];
61+
int b = pair[1];
62+
63+
if(selected[a] && selected[b]) {
64+
canInclude = false;
65+
break;
66+
}
67+
68+
}
69+
70+
if(canInclude) {
71+
dfs(idx+1);
72+
}
73+
74+
selected[idx] = false;
75+
76+
77+
78+
}
79+
}

0 commit comments

Comments
 (0)