-
Notifications
You must be signed in to change notification settings - Fork 1
/
BiggestIncreaseNumbers.java
40 lines (34 loc) · 1.15 KB
/
BiggestIncreaseNumbers.java
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
36
37
38
39
40
package algo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
/**
* https://www.acmicpc.net/problem/11055
* 백준 11055번 문제 가장 큰 증가 부분수열
*/
public class BiggestIncreaseNumbers {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int length = Integer.parseInt(br.readLine());
int[] numbers = new int[length];
int[] dp = new int[length];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < length; i++) {
numbers[i] = Integer.parseInt(st.nextToken());
dp[i] = numbers[i];
}
int max = numbers[0];
for(int i=0; i<length; i++){
for(int j = 0; j<i; j++){
if(numbers[i]>numbers[j]){
dp[i] = Math.max(dp[i], dp[j] + numbers[i]);
}
max = Math.max(max, dp[i]);
}
}
System.out.println(max);
}
}