Skip to content

Commit e3b1929

Browse files
committed
solve: 코딩테스트 문제 풀이 - 18일차
1 parent 3da95ae commit e3b1929

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.Arrays;
5+
6+
public class Main {
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
10+
String str1 = br.readLine();
11+
String str2 = br.readLine();
12+
13+
int n = str1.length();
14+
int m = str2.length();
15+
16+
int[][] dp = new int[n+1][m+1];
17+
18+
for (int i=1; i<=n; i++) {
19+
for (int j=1; j<=m; j++) {
20+
if (str1.charAt(i-1) == str2.charAt(j-1)) {
21+
dp[i][j] = dp[i-1][j-1] + 1;
22+
} else {
23+
dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
24+
}
25+
}
26+
}
27+
28+
System.out.println(dp[n][m]);
29+
}
30+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class Main {
7+
static char[][] canvas;
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
int N = Integer.parseInt(br.readLine());
11+
12+
int height = N;
13+
int weight = 2 * N - 1;
14+
canvas = new char[height][weight];
15+
16+
for (int i=0; i<height; i++) {
17+
Arrays.fill(canvas[i], ' ');
18+
}
19+
20+
draw(0, N-1, N);
21+
22+
StringBuilder sb = new StringBuilder();
23+
for (int i=0; i<height; i++) {
24+
sb.append(canvas[i]).append('\n');
25+
}
26+
System.out.print(sb.toString());
27+
}
28+
29+
public static void draw(int row, int col, int size) {
30+
if (size == 3) {
31+
canvas[row][col] = '*';
32+
canvas[row+1][col-1] = '*';
33+
canvas[row+1][col+1] = '*';
34+
35+
for (int i=-2; i<=2; i++) {
36+
canvas[row+2][col+i] = '*';
37+
}
38+
return;
39+
}
40+
41+
int half = size / 2;
42+
draw(row, col, half);
43+
draw(row + half, col - half, half);
44+
draw(row + half, col + half, half);
45+
}
46+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class Main {
7+
static int N;
8+
static int[][] room;
9+
static int count = 0;
10+
11+
public static void main(String[] args) throws IOException {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
N = Integer.parseInt(br.readLine());
14+
15+
room = new int[N][N];
16+
for (int i=0; i<N; i++) {
17+
String[] input = br.readLine().split(" ");
18+
for (int j=0; j<N; j++) {
19+
room[i][j] = Integer.parseInt(input[j]);
20+
}
21+
}
22+
23+
dfs(1, 0, 0);
24+
System.out.println(count);
25+
}
26+
27+
// 0: 가로, 1: 세로, 2: 대각선
28+
public static void dfs(int x, int y, int dir) {
29+
if (x == N-1 && y == N-1) {
30+
count++;
31+
return;
32+
}
33+
34+
if (dir == 0 || dir == 2) {
35+
int nx = x + 1, ny = y;
36+
if (nx < N && room[ny][nx] == 0) {
37+
dfs(nx, ny, 0);
38+
}
39+
}
40+
if (dir == 1 || dir == 2) {
41+
int ny = y + 1, nx = x;
42+
if (ny < N && room[ny][nx] ==0) {
43+
dfs(nx, ny, 1);
44+
}
45+
}
46+
if (dir == 0 || dir == 1 || dir ==2) {
47+
int nx = x + 1, ny = y + 1;
48+
if (nx < N && ny < N) {
49+
if (room[y][nx] == 0 && room[ny][x] == 0 && room[ny][nx] == 0) {
50+
dfs(nx, ny, 2);
51+
}
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)