https://www.acmicpc.net/problem/20162
package BOJ.dp;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.function.Function;
public class BOJ_20162 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Function<String,Integer> stoi = Integer::parseInt;
int n = stoi.apply(br.readLine());
int[] input = new int[n];
for(int i = 0 ; i < n ; i++){
input[i] = stoi.apply(br.readLine());
}
int result = cal(input,n);
System.out.println(result);
}
private static int cal(int[] input, int n) {
int[] dp = Arrays.copyOf(input,n);
int result= 0;
for(int i = 0 ; i < n ; i++){
result = Math.max(result,input[i]);
for(int j = i+1 ; j < n ; j++){
if(input[i] < input[j] && dp[i] + input[j] > dp[j]){
dp[j] = dp[i] + input[j];
result = Math.max(result,dp[j]);
}
}
}
return result;
}
}
'알고리즘' 카테고리의 다른 글
백준 16568번 엔비스카의 영혼 (JAVA) (0) | 2023.03.03 |
---|---|
백준 5587번 카드 캡터 상근이 (JAVA) (0) | 2023.03.02 |
백준 15723번 n단 논법 (JAVA) (0) | 2023.02.28 |
백준 4889번 안정적인 문자열 (JAVA) (0) | 2023.02.27 |
백준 1326번 폴짝폴짝 (JAVA) (0) | 2023.02.26 |