자바 36

[알고리즘] 플로이드 와샬 알고리즘 - 자바

📖 문제 플로이드 와샬 알고리즘을 직접 만들어보시오 📃 코드 public class Main { static int INF = 1000000; public static void main(String[] args) { int[][] dp = { { 0, 8, 1, INF }, { INF, 0, INF, 1 }, { INF, 2, 0, 9 }, { 4, INF, INF, 0 } }; DP(dp); } private static void DP(int[][] dp) { // result array int result[][] = new int[4][4]; // init for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { result[i][j] = dp[i][..

백준[JAVA] 11279.최대 힙 - 자바

📖 문제 📃 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Collections; import java.util.PriorityQueue; public class Main { static PriorityQueue heap = new PriorityQueue(Collections.reverseOrder()); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int ..

백준[JAVA] 11726.2×n 타일링 - 자바

📖 문제 📃 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static Integer[] dp = new Integer[10008]; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { dp[0] = 0; dp[1] = 1; dp[2] = 2; dp[3] = 3; // dp[n] = dp[n-1] + dp[n-2] int N = Integer.par..

백준[JAVA] 9095.1, 2, 3 더하기 - 자바

📖 문제 📃 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static Integer[] dp = new Integer[11]; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { StringBuilder sb = new StringBuilder(); dp[0] = 0; dp[1] = 1; dp[2] = 2; dp[3] = 4; // dp[4] = ..

백준[JAVA] 1463.1로 만들기 - 자바

📖 문제 📃 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { static Integer[] dp; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int X = Integer.parseInt(br.readLine()); dp = new Integer[X + 1]; dp[0] = dp[1] = 0; System.out.println(recur(X)); } pri..

백준[JAVA] 1259.팰린드롬수 - 자바

📖 문제 📃 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { String s = br.readLine(); if (s.equals("0")) break; boolean palindrome = true; int front = s.length() / 2; int length = s.leng..