티스토리 뷰
LIS 문제중 가장 간단한 형태인것 같다.
숫자들중 순서대로 나보다 큰 숫자들 중 정렬이 가장 많이 되어 있는 숫자를 찾아서 +1을 하여 기록한다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* 정올, 다이나믹, 1871 | |
* 줄세우기 | |
* | |
* @author whitebeard-k | |
* | |
*/ | |
public class Problem1871 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
int[] students = new int[n]; | |
for(int i = 0; i < n; i++) { | |
students[i] = sc.nextInt(); | |
} | |
sc.close(); | |
// int[] students = { 3, 7, 5, 2, 6, 1, 4 }; | |
int[] memo = new int[students.length]; | |
memo[students.length-1] = 1; | |
int LCS = -1; | |
// 뒤에서부터 순착적으로 앞으로 오면서 나보다 큰 숫자들중 | |
// 가장 정렬이 많이 되어 있는 숫자에 +1 을 하여 가장 많이 정렬되어 있는 숫자를 찾는다. | |
for(int i = students.length - 1; i >= 0; i--) { | |
int pivot = students[i]; | |
int max = 0; | |
for(int k = i+1; k < students.length; k++) { | |
if(pivot < students[k] && max < memo[k]) { | |
max = memo[k]; | |
} | |
} | |
memo[i] = max+1; | |
if(LCS < memo[i]) { | |
LCS = memo[i]; | |
} | |
} | |
System.out.println(students.length - LCS); | |
} | |
} |
http://saecom-dalcom.tistory.com/9
http://comganet.github.io/dp/2016/06/03/dp-1007
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=1144&sca=3050
반응형
'알고리즘 > 정올' 카테고리의 다른 글
[정올][다이나믹] 2000 동전교환 (0) | 2016.10.04 |
---|---|
[정올] [문제은행] 1942 하얀모자 (0) | 2016.09.23 |
[정올][다이나믹] 1539 가장높은 탑 쌓기 (0) | 2016.09.20 |
[정올] [다이나믹] 배낭채우기1 (0) | 2016.09.09 |
[정올] [백트래킹] 1840 치즈 (0) | 2016.09.09 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- emr
- 다이나믹
- nodejs
- Hadoop
- ubuntu
- java
- SPARK
- AWS
- 파이썬
- airflow
- 백준
- Python
- bash
- Linux
- error
- 하이브
- oozie
- Tez
- 하둡
- mysql
- yarn
- HIVE
- build
- 알고리즘
- 오류
- 정올
- hbase
- HDFS
- SQL
- S3
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함