Move instantlyaccepts:1018submissions:3620Time limit:4000/2000 MS (java/others)Memory limit:65536/65536 K (java/others)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 mm column of lattice there are several options, the answer to1000000007 100000000 7 Take the mold.
Input
Multiple sets of test data.
Two integers n,m (2\leq n,m\leq 100000)n,m(2≤n,m≤100 000)
Output
An integer representing the answer
Sample Input
4 5
Sample Output
10
Idea: Ans=c (n+m-4,n-2);
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineMoD 1000000007#defineINF 999999999#definePi 4*atan (1)//#pragma COMMENT (linker, "/stack:102400000,102400000")intScan () {intres =0, ch; while( ! (ch = getchar ()) >='0'&& CH <='9' ) ) { if(ch = = EOF)return 1<< - ; } Res= CH-'0' ; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;}voidExtend_euclid (ll A, ll B, ll &x, LL &y) { if(b = =0) {x=1; Y=0; return; } extend_euclid (b, a%b, x, y); LL TMP=x; X=y; Y= tmp-(A/b) *y;} ll Combine1 (ll n,ll m)//calculated number of combinations C (n,m){ll sum=1;//linear calculation for(LL i=1, j=n;i<=m;i++,j--) {sum*=J; Sum%=MoD; ll x, y; Extend_euclid (I,mod,x,y); Sum*= (x%mod+mod)%MoD; Sum%=MoD; } returnsum;}intMain () {ll x,y,z,i,t; while(~SCANF ("%i64d%i64d",&x,&y)) {ll n,k; ll ans=0; K=x-2; N= (x+y)-4; Ans=combine1 (n,k); printf ("%i64d\n", ans); } return 0;}
2016 "Baidu Star"-Preliminary (Astar round2b) 1003 instantaneous movement combination mathematics + inverse element