본문 바로가기

알고리즘 & 자료구조569

백준 24416 package baekjoon.DP; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main24416 { static int A, B; static int[] memo; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); memo = new int[N + 1]; fibonacci(N); fibonacci_dp(N); System.out.printf("%d %d.. 2022. 6. 26.
124 나라의 숫자 package programmers; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; public class OneToFourNumberOfCountry { public String solution(int n) { String answer = ""; int i = 0; while(0 < n) { i = n%3; if(0 == i) { n = n/3 -1; i = 4; }else n /= 3; if (i == 1) { answer = "1" + answer; } if (i == 2) { answer = "2" + answer; } if (i == 4) { answer = "4" + answer; } } .. 2022. 6. 24.
멀쩡한 사각형 package programmers; import java.math.BigInteger; public class PlainSquare { public static long solution(int w, int h) { int gcd = BigInteger.valueOf(w).gcd(BigInteger.valueOf(h)).intValue(); return ((long)w * (long)h) - ((((long)w / gcd) + ((long)h / gcd) - 1) * gcd); } } 2022. 6. 23.
백준 7569 package baekjoon.DFS와BFS; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main7569 { static int M, N, H; static int[][][] map, isVisited; static Queue q = new LinkedList(); static int[] dz = {-1, 0, 0, 0, 0, 1}; static int[] dy = {0, -1, 0, 1, 0, 0}; st.. 2022. 6. 22.
백준 1012 package baekjoon.DFS와BFS; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main1012 { static int T, M, N, K; static int[][] map; static boolean[][] visited; static int[] dy = {-1, 0, 1, 0}; static int[] dx = {0, 1, 0, -1}; static Queue q = new LinkedList.. 2022. 6. 20.
백준 7576 package baekjoon.DFS와BFS; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main7576 { static int M, N, ans = Integer.MAX_VALUE; static int[][] map, visited; static int[] dy = {-1, 0, 1, 0}; static int[] dx = {0, 1, 0, -1}; static.. 2022. 6. 20.