Topic Links:
Move instantly
problem Description
There 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 firstnN rows of M-m columns have several schemes, the answer to the 1000000007 modulo .
Input
Multiple sets of test data.
Two integers n,m (2<= n,m<=100000)
Output
An integer representing the answer
Sample Input
4 5
Sample Output
10
Test instructions
Ideas:
With the number of options that can only go down and to the right, the final result is that one is the same combination, with the fast power and Fermat theorem;
AC code :
#include <bits/stdc++.h>/*#include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring > #include <algorithm> #include <cstdio>*/using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=0x3f3f3f3f;Const intn=2e5+ -;intn,m; LL dp[2*N];intInit () {dp[1]=1; for(intI=2;i<2*n;i++) {Dp[i]=dp[i-1]*(LL) i; Dp[i]%=MoD; }}ll Fastpow (ll X,ll y) {ll ans=1,Base=x; while(y) {if(y&1) {ans*=Base; Ans%=MoD; } Base*=Base; Base%=MoD; Y>>=1; } returnans;}intMain () {Init (); while(SCANF ("%d%d", &n,&m)! =EOF) { if(n==2|| m==2) cout<<"1"<<"\ n"; Else{n-=2; M-=2; LL x=dp[n],y=Dp[m]; LL ans=dp[n+m]*fastpow (x*y%mod,mod-2)%MoD; cout<<ans<<"\ n"; } } return 0;}
hdu-5698 instantaneous movement (number theory + fast power)