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
43
44
45
46
47
48
49
50
51
52
53
54
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_2661 {
static int n;
static boolean flag = false;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st= new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
if (n == 1)
System.out.println(1);
for (int i = 1; i <= 3; i++) {
String res = "";
dfs(i, 1, res);
}
}
static void dfs(int cur, int cnt, String res) {
if (res.length() == n) {
System.out.println(res);
System.exit(0);
}
res += Integer.toString(cur);
int len = cnt/2;
for (int i = 1; i <= len; i++) {
String r1 = res.substring(cnt-i*2, cnt-i);
String r2 = res.substring(cnt-i, cnt);
if (r1.equals(r2)) {
res = res.substring(0, res.length()-1);
return;
}
}
//반복 수열 검사
for (int i = 1; i <= 3; i++) {
dfs(i, cnt+1, res);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
BOJ/JAVA