🐣 알고리즘 삐약/💻 백준 삐약

80 삐약 : 백준 14501| 퇴사 [바킹독 문제 풀이|DP|JAVA]

우주수첩 2024. 6. 18. 22:38
728x90

https://www.acmicpc.net/problem/14501

 

 

package BKD_0x10_DP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class BOJ_14501 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        int[] T = new int[16];
        int[] P = new int[16];
        int[] dp = new int[16];

        for(int i=0;i<N;i++){
            StringTokenizer st = new StringTokenizer(br.readLine());
            T[i] = Integer.parseInt(st.nextToken());
            P[i] = Integer.parseInt(st.nextToken());
        }

        for(int i=0;i<N;i++){
            if(i+T[i]<=N){
                dp[i+T[i]] = Math.max(dp[i+T[i]],dp[i]+P[i]);
            }
            dp[i+1] = Math.max(dp[i+1],dp[i]);
        }

        System.out.println(dp[N]);

    }
}

 

참고 url : https://yeons4every.tistory.com/62

 

백준 14501 : 퇴사 _자바 Java

https://www.acmicpc.net/problem/14501 14501번: 퇴사 첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다. www.acmicpc.net 1일 2일 3일 4일 5일 6일 7일 Ti 3 5 1 1 2 4 2 Pi 10 20 10 20 15 40 200 dp[] 10 10 10 30 45 45 45 pi를

yeons4every.tistory.com

 

728x90