Skip to content

Commit 535a424

Browse files
authored
[20251110] BOJ / G4 / 좋은 수열 / 이준희
1 parent d531e6c commit 535a424

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```java
2+
import java.io.*;
3+
public class Main {
4+
static int N;
5+
static boolean found = false;
6+
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
N = Integer.parseInt(br.readLine().trim());
10+
dfs("", 0);
11+
}
12+
13+
static void dfs(String s, int depth) {
14+
if (found) return;
15+
if (depth == N) {
16+
System.out.println(s);
17+
found = true;
18+
return;
19+
}
20+
for (int i = 1; i <= 3; i++) {
21+
String ns = s + i;
22+
if (goodString(ns)) {
23+
dfs(ns, depth + 1);
24+
}
25+
if (found) return;
26+
}
27+
}
28+
29+
static boolean goodString(String s) {
30+
int len = s.length();
31+
for (int l = 1; l <= len / 2; l++) {
32+
String a = s.substring(len - 2*l, len - l);
33+
String b = s.substring(len - l, len);
34+
if (a.equals(b)) {
35+
return false;
36+
}
37+
}
38+
return true;
39+
}
40+
}
41+
```

0 commit comments

Comments
 (0)