[BZOJ4584] [Apio2016] Rowing
Question Description
In the Seoul, the Han River traverses the east. On the north bank of the Han River, a rowing school is scattered from west to east, numbered sequentially. Each school has several rowing boats. All the rowing boats in the same school have the same color, and the rowing colors of different schools differ. Rowing boats of the same color are considered to be the same. Each school can choose to send some rowing boats to participate in the festival celebrations, or choose not to send any rowing boats to participate. If the numbered schools choose to send rowing boats to participate in the celebrations, then the number of rowing boats sent can be arbitrarily selected between Ai and Bi (AI<=BI). It is worth noting that the school numbered I if choose to send a rowing boat to participate in the celebrations, then it sent the number of rowing boats must be larger than any one of the number of schools sent by the number of rowing. Enter the values of AI and bi for all schools, and find out how many possibilities are possible for a rowing boat, and must have at least one rowboat to attend the celebrations. The two cases are different if and only if there is a certain color of the rowing boat in the number of different
Input
The first line includes an integer n, which indicates the number of schools. The next n rows, each line consists of two positive integers, used to describe a school. The two positive integers included in the first row represent Ai,bi (1<=ai<=bi<=10^9), respectively, n<=500
Output
The output line, an integer, representing all the possible number of plans to send a rowing boat divided by 1,000,000,007 to get the remainder
Input example
2 1 2 2 3
Output example
7
Data size and conventions
See " Input "
Exercises
First discrete to not more than 2n interval, set F (i, j, K) to consider the previous I school, of which the last K school in the interval J of the number of programmes.
The transfer is:
F (i, j, k) = f (I-1, J, K) + F (i-1, J, K-1)/C (Len[j], k-1) * C (Len[j], k) (K > 1)
F (I, j, 1) = f (I-1, J, K) +∑1≤x≤j∑1≤y≤x F (i-1, X, y)
Where Len[j] represents the length of the section J, C (A, b) represents the number of combinations (the number of programs selected from a element B).
It would be nice to have a prefix and an optimization for the second equation.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype > #include <algorithm>using namespace std;const int buffersize = 1 << 16;char buffer[buffersize], *head, *ta Il;inline Char Getchar () {if (Head = = Tail) {int L = fread (buffer, 1, buffersize, stdin); Tail = (Head = buffer) + L;} return *head++;} int read () {int x = 0, F = 1, char c = Getchar (), while (!isdigit (c)) {if (c = = '-') f =-1; c = Getchar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = Getchar ();} return x * f;} #define MAXN 510#define MOD 1000000007#define LL long longint N, num[maxn<<1], cntn;struct line {int L, R; Line () {}line (int _, int __): L (_), R (__) {}int len () {return r-l + 1;}} SCH[MAXN], Ls[maxn<<1];int INVNUM[MAXN], C[MAXN<<1][MAXN], invc[maxn<<1][maxn];void gcd (ll A, ll B, ll& x, ll& y) {if (!b) {x = 1; y = 0; return;} GCD (b, a% B, y, x); Y-= A/b * x;return;} int Inv (ll a) {ll x, Y;GCD (A, MOD, x, y); return (x% mod + mod)% MoD;} void Init () {for (int i = 1; I <= n; i++) Invnum[i] = INV (i), for (int i = 1; i < CNTN; i++) {c[i][0] = invc[i][0] = 1; for (int j = 1; J <= min (Ls[i].len (), N), J + +) C[i][j] = (LL) c[i][j-1] * (Ls[i].len ()-j + 1)% MOD * Invnum[j]% mod,in VC[I][J] = INV (C[i][j]);} return;} int F[MAXN<<1][MAXN], sum[maxn<<1];int Main () {n = read (), for (int i = 1; I <= n; i++) {int L = read (), r = Read () + 1;sch[i] = line (l, R); Num[++cntn] = l; NUM[++CNTN] = r;} Sort (num + 1, num + cntn + 1), CNTN = unique (num + 1, num + CNTN + 1)-num-1;for (int i = 1; i < CNTN; i++) ls[i] = Li NE (Num[i], num[i+1]-1); for (int i = 1; I <= n; i++) SCH[I].L = lower_bound (num + 1, num + cntn + 1, sch[i].l)-Num,sch [I].R = lower_bound (num + 1, num + cntn + 1, SCH[I].R)-num;init (); for (int j = 0; J < Cntn; J + +) Sum[j] = 1;for (int i = 1; I <= N; i++) {for (int j = sch[i].r-1; J >= Sch[i].l; j--) {for (int k = min (i, Ls[j].len ()); K >= 2; k--) {f[j][k] + = (LL) F [j] [K-1] * Invc[j][k-1]% mod * C[j][k]% mod;if (f[j][k] >= mod) f[j][k] = mod;} F[J][1] + = (LL) sum[j-1] * Ls[j].len ()% mod;if (f[j][1] >= MoD) f[j][1]-= MOD;} Sum[0] = 1;for (int j = 1, J < Cntn; J + +) {Sum[j] = sum[j-1];int mxk = min (i, Ls[j].len ()); for (int k = 1; k <= Mxk; k + +) {Sum[j] + = F[j][k];if (sum[j] >= mod) sum[j] = mod;}}} printf ("%d\n", ((Sum[cntn-1]-sum[0])% mod + MoD); return 0;}
Finally the card passed ...
[BZOJ4584] [Apio2016] Rowing