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

미팅 수 최대 더블릿

by 시끄러인마 2019. 2. 20.
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
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int dp[1005= { 0 };
 
int main() {
    int n;
    scanf("%d"&n);
 
    int start, end;
    scanf("%d %d"&start, &end);
    for (int i = 0; i < end; i++)
        dp[i] = 0;
    dp[end= 1;
    int beforeEnd = end;
 
    for (int i = 2; i <= n; i++) {
        scanf("%d %d"&start, &end);
        for (int j = beforeEnd+1; j < end; j++) {            
            dp[j] = dp[beforeEnd];
        }
        if (dp[end== 0)
            dp[end= max(dp[start] + 1, dp[end - 1]);
        else
            dp[end= max(dp[end], max(dp[start] + 1, dp[end - 1]));
        beforeEnd = end;        
    }
 
    printf("%d", dp[end]);
}
cs


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

줄 세우기 더블릿  (0) 2019.02.21
up sequence 더블릿 (LIS)  (0) 2019.02.20
계단 오르기 더블릿  (0) 2019.02.19
점수 인플레이션 더블릿  (0) 2019.02.19
정사각형 수 더블릿  (0) 2019.02.18