본문 바로가기

Java66

[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[ny][.. 2022. 12. 10.
[Java] 백준 [1026] 보물 import java.util.*; public class Solution { // 보물 - Greedy 1026번 public static int minVal(int n, int[] arrA, int[] arrB) { int[] arrTempA = arrA; Integer[] tempB = Arrays.stream(arrB).boxed().toArray(Integer[]::new); Arrays.sort(tempB, Collections.reverseOrder()); int[] arrTempB = Arrays.stream(tempB).mapToInt(Integer::intValue).toArray(); Arrays.sort(arrTempA); int numVal = 0; //for (int i = 0;.. 2022. 12. 10.
[Java] 프로그래머스 [Level-4] 쌍둥이 빌딩 숲 public class Solution { // 쌍둥이 빌딩 숲 // 전체 쌍둥이 빌딩의 수, 측면에서 봤을 때 보이는 빌딩의 수 [경우의 수] // 가장 높은 쌍둥이 빌딩부터 순서대로 배치 // 1, 1 = 11 [1개] // 2, 1 = 1221, 1122 [2개] 1 * 2 // 2, 2 = 2211 [1개] 1 // 3, 1 = 133221, 123321, 122331, 122133, 133122, 113322, 112332, 112233 [8개] 2 * 4 // 3, 2 = 233211, 223311, 221331, 221133, 331221, 331122 [6개] 1 * 4 + 2 // 3, 3 = 332211 [1개] 1 // 4, 1 = [48개] 8 * 6 // 4, 2 = [44개] 6.. 2022. 12. 6.
[Java] 프로그래머스 [Level-3] 순위 public class Solution { // 순위 // Floyd Warshall 알고리즘으로 풀이 public static int solution(int n, int[][] results) { int answer = 0; int zeroCnt = 0; int[][] board = new int[n][n]; // 0 ~ 4 for (int i = 0; i < results.length; i++) { // {4, 3}의 경우 board[results[i][0] - 1][results[i][1] - 1] = 1; // 4는 3에게 이겼으므로 board[3][2] = 1 board[results[i][1] - 1][results[i][0] - 1] = -1; // 3은 4에게 졌으므로 board[2][3].. 2022. 11. 29.
[Java] 프로그래머스 [Level-2] 롤케이크 자르기 import java.util.HashMap; public class Solution { // 롤케이크 자르기 public static int solution(int[] topping) { int answer = 0; HashMap hm1 = new HashMap(); HashMap hm2 = new HashMap(); for (int i = 0; i < topping.length; i++) { hm2.put(topping[i], hm2.getOrDefault(topping[i], 0) + 1); } // hm2 : {1=4, 2=2, 3=1, 4=1} for (int i = 0; i < topping.length; i++) { hm1.put(topping[i], hm1.getOrDefault(toppi.. 2022. 11. 29.
[Java] 프로그래머스 [Level-3] 양과 늑대 import java.util.ArrayList; import java.util.HashMap; public class Solution { // 양과 늑대 static int maxSheepCnt; static HashMap hm; public static void dfs(int currentIndex, int s, int w, ArrayList indexList, int[] info) { if (info[currentIndex] == 0) { s += 1; } else { w += 1; } if (s 2022. 11. 29.