2016 "Baidu Star"-Preliminary (Astar round2b) 1003 instantaneous movement combination mathematics + inverse element

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.