본문 바로가기
알고리즘/DP

2631 줄 세우기

by tryotto 2019. 7. 8.
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
#include <stdio.h>
 
int arr[205= { 0 };
int dp[205= { 0 };
 
int main() {
    int n;
    scanf("%d"&n);
 
    for (int i = 1; i <= n; i++) {
        scanf("%d"&arr[i]);
    }
 
    for (int i = 1; i <= n; i++) {
        int maxV = 0;
        for (int j = 1; j < i; j++) {
            if (arr[j] < arr[i]) {
                if (maxV < dp[j])
                    maxV = dp[j];
            }
        }
 
        dp[i] = maxV + 1;
    }
 
    int rst = 0;
    for (int i = 1; i <= n; i++) {
        if (rst < dp[i])
            rst = dp[i];
    }
 
    printf("%d", n - rst);
}
cs


'알고리즘 > DP' 카테고리의 다른 글

1010 다리놓기  (0) 2019.07.09
2225 합분해  (0) 2019.07.09
1965 상자넣기  (0) 2019.07.08
11054 가장 긴 바이토닉 부분수열  (0) 2019.07.08
1309 동물원  (0) 2019.07.08