[Java] 백준 [11048] 이동하기
public class Solution { // 이동하기 - DP 11048번 static int n = 3; static int m = 4; static int[][] arr = {{1, 2, 3, 4}, {0, 0, 0, 5}, {9, 8, 7, 6}}; static int[] dy = {1, 1, 0}; static int[] dx = {0, 1, 1}; static int[][] dp = new int[n][m]; public static void dfs(int a, int b) { for(int i = 0; i n - 1 || nx > m - 1) { continue; } // dp 갱신 ..
2022. 12. 26.
[Java] 백준 [2178] 미로 탐색
import java.util.LinkedList; import java.util.Queue; public class Solution { // 미로 탐색 - BFS 2178번 // 최단 거리 탐색 BFS static int r = 4; static int c = 6; static int[][] arr = {{1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 1}, {1, 1, 1, 0, 1, 1}}; static boolean[][] visit = {}; static int[] dx = {0, 0, -1, 1}; static int[] dy = {-1, 1, 0, 0}; public static void bfs(int n, int m) { Queue q =..
2022. 12. 24.
[Java] 백준 [7570] 줄 세우기
import java.util.Arrays; public class Solution { // 줄 세우기 - DP 7570번 // 제일 앞 또는 제일 뒤로만 이동 가능 // 연속된 가장 긴 증가하는 부분 수열 이용 static int n = 7; static int[] arr = {3, 7, 5, 2, 6, 1, 4}; static int[] dp = {1, 1, 1, 1, 1, 1, 1}; public static void setLine() { int clisCnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (arr[i] == arr[j] + 1) { dp[i] = Math.max(dp[i], dp[j] + 1); } } } ..
2022. 12. 17.
[Java] 백준 [2631] 줄 세우기
import java.util.Arrays; public class Solution { // 줄 세우기 - DP 2631번 // 이동 위치 제한 없음 // 가장 긴 증가하는 부분 수열(LIS) 이용 static int n = 7; static int[] arr = {3, 7, 5, 2, 6, 1, 4}; static int[] dp = {1, 1, 1, 1, 1, 1, 1}; public static void setLine() { int lisCnt = 0; for (int i = 0; i arr[j] && dp[i]
2022. 12. 17.
[Java] 백준 [9095] 1, 2, 3 더하기
public class Solution { // 1, 2, 3 더하기 - DP 9095번 // n을 1, 2, 3의 합으로 나타내는 방법의 수 static int n = 4; static int[] dp = new int[101]; // 1+1+1+1 // 1+1+2 // 1+2+1 // 2+1+1 // 2+2 // 1+3 // 3+1 public static void main(String[] args) { // TODO Auto-generated method stub // n은 1일 때 1 // 2일 때 1+1, 2 // 3일 때 1+1+1, 1+2, 2+1, 3 // 4는 1+3/2+2/3+1로 나타낼 수 있음 // 1+(1+1+1)/2+(1+1)/3+(1) // 1+(1+2)/2+(2) // 1+(..
2022. 12. 16.