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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| #include <cstdio> #include <utility> #define fi first #define se second using namespace std; template <class Type> void read(Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; if (flag) x = ~x + 1; } template <class Type, class ...rest> void read(Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write(Type x) { if (x < 0) putchar('-'), x = ~x + 1; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } typedef long long LL; typedef pair <int, int> PII; const int N = 5e5 + 10, M = 510, mod = 1e9 + 7; PII p[M]; bool vis[M]; int fact[N], ifact[N]; int n, Ax, Ay, Bx, By, f[M]; int binpow (int b, int k = mod - 2) { int res = 1; for (; k; k >>= 1, b = (LL)b * b % mod) if (k & 1) res = (LL)res * b % mod; return res; } void init () { fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = (LL)fact[i - 1] * i % mod; ifact[N - 1] = binpow(fact[N - 1]); for (int i = N - 1; i; --i) ifact[i - 1] = (LL)ifact[i] * i % mod; } int calc (int a, int b) { return (LL)ifact[a] * ifact[b] % mod * fact[a + b] % mod; } int dfs (int x) { if (vis[x]) return f[x]; vis[x] = true; f[x] = calc(p[x].fi, p[x].se); for (int i = 0; i <= n; ++i) if (p[i].fi <= p[x].fi && p[i].se <= p[x].se && p[i] != p[x]) f[x] = (f[x] - (LL)dfs(i) * calc(p[x].fi - p[i].fi, p[x].se - p[i].se)) % mod; return f[x]; } int main () { init(); read(p[0].fi, p[0].se, n, Ax, Ay, Bx, By); for (int i = 1; i <= n; ++i) read(p[i].fi, p[i].se); int D = Ax * By - Bx * Ay; for (int i = 0; i <= n; ++i) { int D1 = p[i].fi * By - Bx * p[i].se, D2 = Ax * p[i].se - p[i].fi * Ay; if (D1 % D || D2 % D) vis[i] = true; p[i].fi = D1 / D, p[i].se = D2 / D; if (p[i].fi < 0 || p[i].se < 0) vis[i] = true; for (int j = 0; j < i && !vis[i]; ++j) if (p[i] == p[j]) vis[i] = true; } write((dfs(0) + mod) % mod); return 0; }
|