728x90
반응형
https://www.acmicpc.net/problem/11052
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N;
static int[] arr;
static int[] dp;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
arr = new int[N + 1];
dp = new int[N + 1];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 1; i <= N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
System.out.println(search());
}
static int search() {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
dp[i] = Math.max(dp[i], dp[i - j] + arr[j]);
}
}
return dp[N];
}
}
|
cs |
728x90
'Algorithm > BOJ' 카테고리의 다른 글
백준) 7576_토마토 (1) | 2023.05.17 |
---|---|
백준) 2133_타일 채우기 (0) | 2023.05.16 |
백준) 1074_Z (0) | 2023.05.16 |
백준) 11003_최솟값 찾기 (2) | 2023.05.14 |
백준) 21276_계보 복원가 호석 (2) | 2023.05.13 |