This question just finished reading, thought, did not train of thought, on the solution =
But I have to say, finding this is really powerful, link: http://blog.csdn.net/qwb492859377/article/details/51478117
This I just looked at his ideas, then the code to write their own, then handed up is 1 A, I feel good solution should be like this, Orz
To first look at his ideas, and now I am adding some of my understanding: first, you want to see the row, column, first say line, from 1 to n,1 and n can not go, because 1 is the beginning, n is OK, so you have n-2 kind of choice, you can enumerate X from 1 to n-2, equivalent to high school, There are several cases where x is the same ball in a n-2 box. The same is true for columns, but note that they also multiply at the same x, which is obvious because it is impossible to add.
The last ANS will also add 1, because from 1, 1 straight to n,m this situation is not counted. There is a C (n,k), this is a set of templates, nothing to say.
#include <bits/stdc++.h>using namespacestd;Const intinf=0x3f3f3f3f; typedefLong Longll;#definePI (a) printf ("%d\n", a)#defineSI (n) scanf ("%d",& (n))#defineSII (n,m) scanf ("%d%d",& (N),& (M))#defineCLE (A,val) memset (A, (Val), sizeof (a))#defineRep (i,b) for (int i=0;i< (b); i++)#defineREP (I,A,B) for (int i= (a); i<= (b); i++)#defineREReP (I,A,B) for (int i= (a); i>= (b); i--)Const Doubleeps= 1e-9 ;/*/////////////////////////c o d i n g S p a C e/////////////////////////*/Const intmaxn=100000+5 ;Const intmod=1e9+7; ll JIECH[MAXN];//an array of factorial modulointn,m;//Quick Power Templatell Mod_pow (ll x,ll n,ll MoD) {ll res=1; while(n>0){ if(n&1) res=res*x%MoD; X=x*x%MoD; N>>=1; } returnRes;}//C (n,k) function (n below c, K above c)//restriction: MoD must be a prime number, because it is obtained by the Fermat theoremll C (intNintk) {ll d= (Jiech[k]*jiech[n-k])%MOD; return(Jiech[n]*mod_pow (d,mod-2, MOD))%MOD;}intMain () {//First, we play the table factorial to take the modulus groupjiech[1]=jiech[0]=1; for(intI=2; i<maxn;i++) {Jiech[i]= (jiech[i-1]*i)%MOD; } while(~SII (n,m)) { intk=min (n,m); intK2=Max (n,m); ll ans=0; //to follow the small loop for(intI=1; i<=k-2; i++) {ans+=c (K-2, i) *c (k2-2, i); Ans%=MOD; } printf ("%lld\n", ans+1); } return 0;}
HDU 5698 instantaneous movement (permutation combination)