Move instantly
Time limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1422 Accepted Submission (s): 684
problem DescriptionThere is an infinitely large rectangle, initially when you are in the upper left corner (i.e. the first row of the first column), each time you can select a lower right lattice, and teleport past (such as the red lattice from which can be directly teleport to the blue lattice), the nth row of m There are several options for the grid of columns, and the answer is 1000000007 .
Inputmultiple sets of test data.
Two integers n,m(2≤n,m≤100000)
OutputAn integer representing the answer
Sample Input4 5
Sample OutputTen
Source2016 "Baidu Star"-Preliminary round (Astar round2b) x and Y are considered separately, between (N,M) can choose to walk I step. You need to select the row C (n-2,i) and I-Step corresponding column C (m-2,i) for the I step. Multiply them. Suppose M<=n
#include <iostream>#include<cstdio>#include<cstring>#defineN 200001#defineM 1000000007#definell Long Longusing namespaceStd;ll Fac[n]={1,1},inv[n]={1,1},f[n]={1,1};intN,m;ll C (ll a,ll b) {returnfac[a]*inv[b]%m*inv[a-b]%M;}intMain () { for(intI=2; i<n;i++) {Fac[i]=fac[i-1]*i%M; F[i]= (m-m/i) *f[m%i]%M; Inv[i]=inv[i-1]*f[i]%M; } while(~SCANF ("%d%d", &n,&m)) printf ("%lld\n", C (m+n-4, M-2)); return 0;}
hdu5698 instantaneous movement (combination number, inverse)