Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions lkhyun/202502/04 BOJ 골드4 파이프 옮기기2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
```java
import java.util.Scanner;

public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[][] matrix = new int[N][N];
long[][][] dp = new long[3][N][N]; // 0:가로 1:세로 2:대각선선
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
matrix[i][j] = sc.nextInt();
}
}
for(int i=1;i<N;i++){
if(matrix[0][i] == 1){
break;
}
dp[0][0][i] = 1;
}

for (int i = 1; i < N; i++) {
for (int j = 1; j < N; j++) {
if(matrix[i][j] == 1){
dp[0][i][j] = 0;
dp[1][i][j] = 0;
dp[2][i][j] = 0;
}
Comment on lines +24 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 왜 필요한건지 궁금해요

else{
boolean left = matrix[i][j-1] == 0;
boolean up = matrix[i-1][j] == 0;
boolean diagonal = matrix[i-1][j-1] == 0;
if(left&&up&&diagonal){
dp[0][i][j] = dp[0][i][j-1] + dp[2][i][j-1];
dp[1][i][j] = dp[1][i-1][j] + dp[2][i-1][j];
dp[2][i][j] = dp[0][i-1][j-1] + dp[1][i-1][j-1] + dp[2][i-1][j-1];
}
else if(left&&diagonal){
dp[0][i][j] = dp[0][i][j-1] + dp[2][i][j-1];
dp[1][i][j] = 0;
dp[2][i][j] = 0;
}
else if(diagonal&&up){
dp[0][i][j] = 0;
dp[1][i][j] = dp[1][i-1][j] + dp[2][i-1][j];
dp[2][i][j] = 0;
}
else if(left&&up){
dp[0][i][j] = dp[0][i][j-1];
dp[1][i][j] = dp[1][i-1][j];
dp[2][i][j] = 0;
}
else if(left){
dp[0][i][j] = dp[0][i][j-1];
dp[1][i][j] = 0;
dp[2][i][j] = 0;
}
else if(up){
dp[0][i][j] = 0;
dp[1][i][j] = dp[1][i-1][j];
dp[2][i][j] = 0;
}
else{
dp[0][i][j] = 0;
dp[1][i][j] = 0;
dp[2][i][j] = 0;
}
}
}
}

System.out.println(dp[0][N-1][N-1]+dp[1][N-1][N-1]+dp[2][N-1][N-1]);
}
}

```