[Java] 프로그래머스 [Level-2] 디펜스 게임
import java.util.PriorityQueue; public class Solution { // 디펜스 게임 public static int solution(int n, int k, int[] enemy) { int answer = enemy.length; // 모든 라운드 클리어 가능할 경우의 리턴 값 PriorityQueue pq = new PriorityQueue(); // 무적권을 사용해 해치울 적의 수를 남기기 위한 우선순위 큐 // 디펜스 게임 시작 for(int i = 0; i < enemy.length; i++) { // 4, 2, 4, 5, 3, 3, 1 pq.offer(enemy[i]); // 4 // 2, 4 // 2, 4, 4 // 2, 4, 4, 5 // 3, 4, 4, ..
2022. 12. 27.
[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 갱신 ..
2022. 12. 26.
[Java] 백준 [2178] 미로 탐색
import java.util.LinkedList; import java.util.Queue; public class Solution { // 미로 탐색 - BFS 2178번 // 최단 거리 탐색 BFS static int r = 4; static int c = 6; static int[][] arr = {{1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 1}, {1, 1, 1, 0, 1, 1}}; static boolean[][] visit = {}; static int[] dx = {0, 0, -1, 1}; static int[] dy = {-1, 1, 0, 0}; public static void bfs(int n, int m) { Queue q =..
2022. 12. 24.