반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 코테
- Trino
- bigdata engineering
- bigdata engineer
- Kafka
- BigData
- 개발
- hadoop
- 자바
- Data Engineering
- apache iceberg
- Data Engineer
- Spark
- 코딩
- 코딩테스트
- Apache Kafka
- 코엑스맛집
- 코엑스
- pyspark
- Iceberg
- java
- HIVE
- 영어
- 알고리즘
- 프로그래머스
- 여행
- 백준
- 삼성역맛집
- 용인맛집
- 맛집
Archives
- Today
- Total
지구정복
[DP] 백준 - 가장 큰 증가하는 부분 수열 본문
728x90
반응형
-자바
package dp;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class LIS1 {
private static BufferedWriter bw =
new BufferedWriter( new OutputStreamWriter(System.out));
private static int n, result;
private static int[] a, d;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
n = Integer.parseInt( br.readLine() );
a = new int[n+1];
d = new int[n+1];
st = new StringTokenizer( br.readLine() );
for( int i=1; i<=n; i++ ) a[i] = Integer.parseInt( st.nextToken() );
d[1] = a[1];
for( int i=2; i<=n; i++ ) {
d[i] = a[i];
for( int j=1; j<i; j++ ) {
if( a[i] > a[j] ) d[i] = Math.max( d[i], d[j]+a[i] );
}
}
for( int i=1; i<=n; i++ ) result = Math.max( result, d[i] );
bw.write( result + "\n" );
bw.flush();
bw.close();
br.close();
}
}
-파이썬
n = int(input())
a = [0] + list( map( int, input().split() ) )
d = [0] * (n+1)
d[1] = a[1]
for i in range( 2, n+1 ):
d[i] = a[i]
for j in range( 1, i ):
if a[i] > a[j]:
d[i] = max( d[i], d[j]+a[i] )
print( max( d ) )
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[수학] 백준 - 최대공약수와 최대공배수 (0) | 2021.07.14 |
---|---|
[문자열] 백준 - 단어 뒤집기 (0) | 2021.07.14 |
[DP] 백준 - 가장 긴 감소하는 부분수열 (0) | 2021.07.14 |
[DP] 백준 - 1,2,3 더하기 5 (0) | 2021.07.14 |
[DP] 백준 - 카드 구매하기 2 (0) | 2021.07.13 |
Comments