#dp#D 导出子图

题目


分析


代码

#include <cstdio>
#include <cctype>
#include <algorithm>
#define rr register
using namespace std;
const int N = 4011, mod = 1000000007;
struct rec {
    int l, r;
} a[N >> 1];
int n, nxt[N], dp[N >> 1][N], ans;
inline signed iut() {
    rr int ans = 0;
    rr char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();
    return ans;
}
inline signed mo(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
bool cmp(rec x, rec y) { return x.l < y.l; }
signed main() {
    freopen("graph.in", "r", stdin);
    freopen("graph.out", "w", stdout);
    n = iut();
    for (rr int i = 1; i <= n; ++i) a[i] = (rec){ iut(), iut() };
    sort(a + 1, a + 1 + n, cmp);
    for (rr int i = 1, j = 1; i < N; ++i) {
        for (; j <= n && a[j].l <= i; ++j)
            ;
        nxt[i] = j;
    }
    for (rr int i = 1; i <= n; ++i) dp[i + 1][a[i].r] = 1;
    for (rr int i = 1; i <= n; ++i)
        for (rr int j = 1; j < N; ++j) {
            dp[i + 1][j] = mo(dp[i + 1][j], dp[i][j]);
            if (a[i].l > j)
                continue;
            if (a[i].r > j)
                dp[nxt[j]][a[i].r] = mo(dp[nxt[j]][a[i].r], dp[i][j]);
            else
                dp[nxt[a[i].r]][j] = mo(dp[nxt[a[i].r]][j], dp[i][j]);
        }
    for (rr int j = 1; j < N; ++j) ans = mo(ans, dp[n + 1][j]);
    return !printf("%d", ans);
}
posted @ 2020-11-25 19:46  lemondinosaur  阅读(162)  评论(0编辑  收藏  举报