Ideas:
Is difficult
// C (M + N, M) * C (Q + M-P, Q)-C (N + M-P, N) * C (M + Q, M );
Code:
# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "stack" # include "algorithm" # include "iostream" using namespace std; # define ll long # define mod 100000007 // C (M + N, M) * C (Q + M-P, Q)-C (N + M-P, N) * C (M + Q, M); ll inverse [100005]; ll power (ll a, ll B) // if mod is a prime number, the reverse element of B is actually B ^ (mod-2) {ll ans = 1; while (B) {if (B & 1) ans = (ans * a) % mod; a = (a * a) % mod; B >>= 1;} return ans;} ll exgcd (ll a, ll B, ll & x , Ll & y) {if (B = 0) {x = 1; y = 0; return a;} ll t, r = exgcd (B, a % B, x, y); t = x; x = y; y = t-a/B * y; return r;} ll get_inverse (ll) // exgcd reverse element {ll x, y; exgcd (a, mod, x, y); return (x % mod + mod) % mod;} ll fc (ll n, ll m) {/* ll t1, t2; // if the data is small, multiply it directly to obtain the last reverse element fast t1 = t2 = 1; for (ll I = n; i> m; I --) {t1 = (t1 * I) % mod; t2 = (t2 * (I-m) % mod;} return t1 * get_inverse (t2) % mod; */ll ans = 1; // if the data is large, the reverse element used for preprocessing is multiplied by the reverse element for (ll I = n; I> m; I --) {ans = (Ans * I) % mod; ans = (ans * inverse [I-m]) % mod;} return ans;} int main () {ll m, n, p, q; for (int I = 1; I <= 100000; I ++) inverse [I] = power (I, mod-2 ); // pre-processing inverse element for (int I = 1; I <= 100000; I ++) inverse [I] = get_inverse (I ); // pre-processing reverse element while (scanf ("% lld", & m, & n, & p, & q )! =-1) {ll a, B, c, d, ans; a = fc (m + n, m); B = fc (q + m-p, q ); c = fc (n + m-p, n); d = fc (m + q, m); ans = (a * B) % mod-(c * d) % mod; ans = (ans % mod + mod) % mod; printf ("% lld \ n", ans);} return 0 ;}
[Combination number modulo-inverse element calculation template] zoj 3624 Count Path Pair