썸네일 동전교환 (냅색 알고리즘) import java.util.Arrays; import java.util.Scanner; public class Main { //냅색 알고리즘 static int n, m; static int[] coins; //동전 종류 목록 static int[] dynamic; //최소 동전 개수 public int solution() { dynamic[0] = 0; for(int i=0; i
썸네일 최대점수 구하기 (냅색 알고리즘) import java.util.Scanner; public class Main06 { //냅색 알고리즘 public static void main(String[] args) { Scanner kb = new Scanner(System.in); int n = kb.nextInt(); int m = kb.nextInt(); int[] dynamic = new int[m+1]; for(int i=0; i=time; j--) { //앞에서부터 돌면 중복 //뒤에서부터 돌아야 중복 회피 dynamic[j] = Math.max(dynamic[j], dynamic[j-time]+score); } } System.out.println(dynamic[m]); } }
썸네일 뮤직비디오(결정알고리즘) import java.util.Arrays; import java.util.Scanner; public class Main { public int count(int[] arr, int capacity) { int cnt = 1; int sum = 0; for(int x : arr) { if(sum+x > capacity) { cnt++; sum = x; } else { sum += x; } } return cnt; } public int solution(int n, int cd, int[] arr) { int ans = 0; int lt = Arrays.stream(arr).max().getAsInt(); int rt = Arrays.stream(arr).sum(); while(lt
썸네일 섬나라 아일랜드 (BFS, DFS) BFS import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; class Node{ int x; int y; public Node(int x, int y) { this.x = x; this.y = y; } } public class Main { static int answer = 0, n; static int[] dx = {1, 1, 1, -1, -1, -1, 0, 0}; static int[] dy = {1, 0, -1, 1, 0, -1, 1, -1}; static int[][] board; static Queue queue = new LinkedList(); public void BFS(int x, int y) { ..
썸네일 토마토(BFS 활용) import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; class Tomato{ int x, y; public Tomato(int x, int y) { this.x = x; this.y = y; } } public class Main { static int[][] box; static int[][] day; static int[] dx = {1, -1, 0, 0}; static int[] dy = {0, 0, 1, -1}; static int n, m; static Queue queue = new LinkedList(); public void BFS() { while(!queue.isEmpty()) { Tomato to..
썸네일 후위연산식 문제 (Stack) import java.util.Scanner; import java.util.Stack; public class Main { public int solution(String str) { int ans = 0; Stack stk = new Stack(); for(char x : str.toCharArray()) { if(Character.isDigit(x)) stk.push(x-48); else { int rt = stk.pop(); int lt = stk.pop(); if(x == '+') stk.push((lt) + (rt)); else if(x == '-') stk.push((lt) - (rt)); else if(x == '*') stk.push((lt) * (rt)); else if(x == '/'..