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 34 35 36 37 38 39 40 41 42 43 44 45
| #include <cctype> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; inline int read(int f = 1, int x = 0, char ch = ' ') { while(!isdigit(ch = getchar())) if(ch == '-') f =-1; while(isdigit(ch)) x = x*10+ch-'0', ch = getchar(); return f*x; } const int N = 4e3+5, P = 1e9+7; int n; pair<int, int> p[N]; int pl[N], pr[N], f[N][N], g[N][N], h[N][N], ans; int main() { n = read(); for(int i = 1; i <= n; ++i) { int l = read(), r = read(); p[i] = make_pair(r, l); } sort(p+1, p+1+n); for(int i = 1; i <= n; ++i) pl[i] = p[i].second, pr[i] = p[i].first; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= i; ++j) { if(pl[j] < pl[i]&&pl[i] <= pr[j]) { int k = lower_bound(pr+1, pr+1+n, pl[i])-pr-1; f[i][j] = (1+g[j][k])%P; } else if(pl[i] <= pl[j]&&pr[j] <= pr[i]) { int k = lower_bound(pr+1, pr+1+n, pl[j])-pr-1; f[i][j] = (1+g[i][k])%P; } ans = (ans+f[i][j])%P, g[i][j] = (g[i][j-1]+f[i][j])%P; } } printf("%d\n", ans); return 0; }
|