Topic links: https://atcoder.jp/contests/abc154/tasks/abc154_f
Subject to the effect
Provided $ (r, c) $ is an integer of two-dimensional point coordinate axes, and r, c are natural numbers.
Defined $ f (r, c) $ $ from (0, 0) to the sum of all paths $ $ (r, c) $ (the right can only be up or down).
Given two points now $ (r1, c1) $ and $ (r2, c2) $$ (r1 \ leq r2, c1 \ leq c2) $, seeking $ \ displaystyle \ sum_ {i = r1} ^ {r2} \ sum_ {j = c1} ^ {c2} f (i, j) $, $ 10 and $ ^ 7 + 9 mod.
analysis
Easy to see, $ f (r, c) = \ binom {r + c} {r} $.
而$\displaystyle \sum_{j=c1}^{c2} f(r, j) = \displaystyle \sum_{j=c1}^{c2} \binom{r + j}{r} = \displaystyle \sum_{j=0}^{c2} \binom{r + j}{r} - \displaystyle \sum_{j=0}^{c1 - 1} \binom{r + j}{r}$。
Using Zhu Shijie identity, available $ \ displaystyle \ sum_ {j = c1} ^ {c2} f (r, j) = \ binom {r + c2 + 1} {r + 1} - \ binom {r + c1} { r + 1} $.
code show as below
. 1 #include <bits / STDC ++ H.> 2 the using namespace STD; . 3 . 4 / * ------------------- the Define the Start ---------- --------- * / . 5 typedef BOOL BL; // boolean . 6 typedef char SB; // signed 1 byte, 8 . 7 typedef unsigned char UB; // unsigned byte 1, 8 bit . 8 typedef short SW; // signed short, 16 . 9 typedef unsigned shortThe UW; // unsigned short, 16 10 typedef Long SDW; // signed integer, 32-bit . 11 typedef unsigned Long UDWs; // unsigned integer, 32-bit 12 is typedef Long Long SLL; // there unsigned long integer, 64-bit 13 is typedef unsigned long long ULL; // unsigned long, 64 14 typedef char CH; // single character 15 typedef a float R32; // 单精度浮点数 16 typedef double R64; // 双精度浮点数 17 18 #define Rep(i, n) for (register SDW i = 0; i < (n); ++i) 19 #define For(i, s, t) for (register SDW i = (s); i <= (t); ++i) 20 #define rFor(i, t, s) for (register SDW i = (t); i >= (s); --i) 21 #define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) 22 #define ms0(a) memset(a,0,sizeof(a)) 23 #define msI(a) memset(a,0x7f,sizeof(a)) 24 #define LOWBIT(x) ((x)&(-x)) 25 26 #define MP make_pair 27 #define PB push_back 28 #define ft first 29 #define sd second 30 31 #define pr(x) cout << #x << " = " << x << " " 32 #define prln(x) cout << #x << " = " << x << endl 33 34 const ULL mod = 1e9 + 7; //常用模数(可根据题目需要修改) 35 const ULL inf = 0x7fffffff; const36used to represent infinity// 0x7fffffffffffffffLL infLL = ULL; // used to represent infinity 37 [ / * ------------------- -------------- the Define End ----- * / 38 is 39 const UDWs maxN = 1e6 + . 7 ; 40 SLL R1, C1, R2, C2; 41 is SLL ANS; 42 is 43 is SLL FAC [maxN * 2 ]; 44 is void init_fact () { 45 FAC [ 0 ] = . 1 ; 46 is the For (I, . 1 , 2 * maxN - . 1 ) { 47 FAC [I] = (I * FAC [I - . 1])% MOD; 48 } 49 } 50 51 is void INPUT () { 52 is CIN R1 >> R2 >> >> >> C1 C2; 53 is init_fact (); 54 is } 55 56 is // AX + by = GCD (A, b) D = 57 is // extended Euclidean algorithm 58 / * * 59 * a * b * Y = X +. 1 60 * ab If prime, solvability 61 is * X is a b on the inverse element 62 is * Y b is the inverse on a 63 * 64 * proof: 65 * a * b * X% + Y% b b = b. 1% 66 * A * X% B =. 1% B 67 * A * X =. 1 (MOD B) 68 * / 69 inline void ex_gcd (SLL A, SLL B, SLL & X, SLL & Y, SLL & D) { 70 IF (! B) { 71 is D = A, X = . 1 , Y = 0 ; 72 } 73 is the else { 74 ex_gcd (B, A% B, Y, X, D); 75 Y - = X * (A / B); 76 } 77 } 78 79 // find a inverse element for p, and if there is, return -1 80 @a p-prime, inverse is only present 81 inline SLL inv_mod (SLL a, SLL p = MOD) { 82 SLL D, X, Y; 83 ex_gcd (a, p, X, Y, D); 84 return D = = . 1 (X% P + P)% P: -? . 1 ; 85 } 86 87 inline SLL comb_mod (SLL m, SLL n-) { 88 SLL RET; 89 90 IF (m> n-) { 91 is the swap (m, n- ); 92 } 93 94 RET = (FAC [n-] * inv_mod (FAC [m], MOD))% MOD; 95 RET = (RET * inv_mod (FAC [n-- m], MOD))% mod; 96 97 return ret; 98 } 99 100 void solve(){ 101 For(i, r1, r2) { 102 ans = (ans + comb_mod(i + 1, c2 + i + 1) - comb_mod(i + 1, c1 + i) + mod) % mod; 103 } 104 } 105 106 void output(){ 107 cout << ans << endl; 108 } 109 110 int main() { 111 input(); 112 solve(); 113 output(); 114 return 0; 115 }