반응형
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 |
Tags
- BigData
- Apache Kafka
- pyspark
- Kafka
- Iceberg
- 여행
- hadoop
- 코딩테스트
- 영어
- 프로그래머스
- apache iceberg
- 코엑스맛집
- 용인맛집
- Trino
- Spark
- Data Engineer
- 백준
- bigdata engineer
- 맛집
- Data Engineering
- 코테
- HIVE
- bigdata engineering
- 개발
- java
- 코엑스
- 삼성역맛집
- 알고리즘
- 코딩
- 자바
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 LIS2 {
private static BufferedWriter bw =
new BufferedWriter( new OutputStreamWriter(System.out));
private static int n, result;
private static int[] a, d;
private static StringTokenizer st;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt( br.readLine() );
a = new int[n+1];
d = new int[n+1];
d[1] = 1;
st = new StringTokenizer( br.readLine() );
for( int i=1; i<=n; i++ ) a[i] = Integer.parseInt( st.nextToken() );
for( int i=2; i<=n; i++ ) {
d[i] = 1;
for( int j=1; j<i; j++ )
if( a[i]>a[j] && d[i]<=d[j] ) d[i] = d[j]+1;
}
for( int i : d ) result = Math.max( result, i );
bw.write( result + "\n" );
bw.flush();
bw.close();
br.close();
}//main end
}
-파이썬
n = int( input() )
a = [0] + list( map( int, input().split() ) )
d = [0] * (n+1)
d[1] = 1
for i in range(2, n+1):
d[i] = 1
for j in range(1, i):
if a[i]>a[j] and d[i]<=d[j]:
d[i] = d[j] + 1
print( max(d) )
728x90
반응형
'데이터 엔지니어링 정복 > Algorithm' 카테고리의 다른 글
[DP] 백준 - 피보나치 수 5 (0) | 2021.07.15 |
---|---|
[DP] 백준 - 제곱수의 합 (0) | 2021.07.15 |
[수학] 백준 - 최대공약수와 최대공배수 (0) | 2021.07.14 |
[문자열] 백준 - 단어 뒤집기 (0) | 2021.07.14 |
[DP] 백준 - 가장 큰 증가하는 부분 수열 (0) | 2021.07.14 |