[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.
[Java] 프로그래머스 [Level-3] 숫자 타자 대회
public class Solution { // 숫자 타자 대회 public static int[][] weight = { // 가중치 {1, 7, 6, 7, 5, 4, 5, 3, 2, 3}, // 0에서부터 0 ~ 9까지의 가중치 {7, 1, 2, 4, 2, 3, 5, 4, 5, 6}, // 1에서부터 0 ~ 9까지의 가중치 {6, 2, 1, 2, 3, 2, 3, 5, 4, 5}, // 2에서부터 0 ~ 9까지의 가중치 {7, 4, 2, 1, 5, 3, 2, 6, 5, 4}, // 3에서부터 0 ~ 9까지의 가중치 {5, 2, 3, 5, 1, 2, 4, 2, 3, 5}, // 4에서부터 0 ~ 9까지의 가중치 {4, 3, 2, 3, 2, 1, 2, 3, 2, 3}, // 5에서부터 0 ~ 9까지의 가중..
2022. 12. 13.
[Java] 백준 [1303] 전쟁 - 전투
import java.util.ArrayList; public class Solution { // 전쟁 - 전투 - DFS 1303번 static int n = 5; static int m = 5; static char[][] arr = {{'W','B','W','W','W'}, {'W','W','W','W','W'}, {'B','B','B','B','B'}, {'B','B','B','W','W'}, {'W','W','W','W','W'}}; static boolean[][] visit = new boolean[5][5]; static int[] dy = {-1, 1, 0, 0}; static int[] dx = {0, 0, -1, 1}; static ArrayList wList = new ArrayLi..
2022. 12. 10.