페이지

2543번: 초고속철도

https://www.acmicpc.net/problem/2543


#include<stdio.h>
#include<algorithm>
using namespace std;
const int mod = 20070713, MAX_N = 100000;
int dp[MAX_N + 1], n;
struct s {
    int x, y;
    s() {}
    s(int _x, int _y)
        :x(_x), y(_y) {}
    bool operator<(s i) const {
        return y < i.y;
    }
}st[MAX_N + 1];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d %d", &st[i].x, &st[i].y);
    sort(st + 1, st + 1 + n);
    dp[0] = 1;
    for (int i = 1; i <= n; i++)
        dp[i] = (dp[i - 1] + dp[upper_bound(st + 1, st + i, s(0, st[i].x)) - st - 1]) % mod;
    printf("%d", dp[n]);
    return 0;
}

댓글 없음 :

댓글 쓰기