hdu5698 instantaneous movement (combination number, inverse)

Source: Internet
Author: User

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)

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.