본문 바로가기

DP3

[프로그래머스] 땅따먹기 - 자바(Java), DP(Dynamic Programming) 문제 https://programmers.co.kr/learn/courses/30/lessons/12913 풀이 DFS를 사용해 완전 탐색으로 풀이하면 시간 초과로 실패하기 때문에, DP(Dynamic Programming)를 사용하여 풀이해야 한다. import java.util.*; class Solution { int solution(int[][] land) { int n = land.length; for(int i = 1; i < n; i++) { //land[i][j] : i행 j열로 내려왔을 때의 최대 값 land[i][0] += Math.max(land[i-1][1], Math.max(land[i-1][2], land[i-1][3])); land[i][1] += Math.max(land[i-.. 2022. 1. 10.
[알고리즘/백준] 1003 피보나치 함수 - 자바(Java), DP 문제 https://www.acmicpc.net/problem/1003 풀이 코드 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)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t; i.. 2021. 10. 13.
[알고리즘/백준] 14051 퇴사 - 자바(Java), DP, 삼성 SW 역량테스트 기출 문제 https://www.acmicpc.net/problem/14501 풀이 코드 DP를 사용하여 풀이 dy[i] : i번째 날의 최대 수입 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine(.. 2021. 10. 12.