[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.