hdu5698 Baidu Star 2016round2b the 3rd question

Source: Internet
Author: User

The first problem is to find a regular formula, and then the knowledge of combinatorial mathematics.

The question is that there are several options for the format of row m in column N, and we can use the hand method to list all answers when N and m compare hours

For example, I list the following 8*8 matrices

924 462  About  -   -  7   1   0462 252 126  About   +  6   1   0 About 126  -   *   the  5   1   0 -   About   *   -  Ten  4   1   0 -   +   the  Ten  6   3   1   07   6   5   4   3   2   1   01   1   1   1   1   1   1   00   0   0   0   0   0   0   1

The number on the matrix represents the total number of scenarios from that location to the bottom right corner.

The value of each position is also simple, which is to add up all the numbers in the lower right corner.

So, to look at this matrix upside down, is the desired result matrix.

The law is also easy to find, first of all, the matrix is symmetrical, so I am only considering the situation of m>=n.

Then, you can find that the number of each position is a combination of C (M + n-4, n-2)

The last is to find the combined number of modulo, C (M + n-4, n-2)%

However, I did not do the problem for many years, and will not combine the number of modulo. Find the previous template, is the Bamboo master wrote, looked at the long time only understand, when I finished, the game just ended.

After the game is over, it's a t_t.

Here is the code

/** Baidu/win.cpp * Created on:2016-5-22 * Author:ben*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctime>#include<iostream>#include<algorithm>#include<queue>#include<Set>#include<map>#include<stack>#include<string>#include<vector>#include<deque>#include<list>#include<functional>#include<numeric>#include<cctype>using namespaceStd;typedefLong LongLL; ll EXT_GCD (ll A, ll B, LL&x, LL &y) {if(b = =0) {x=1, y =0; returnA; } LL ret= EXT_GCD (b, a%b, y, x); Y-= A/b *x; returnret;} ll Inv (ll A,intm) {///finding the inverse of the divisor A to m;LL d, x, y, t =(LL) m; D=EXT_GCD (A, t, X, y); if(d = =1)        return(x% t + t)%T; return-1;}voidWorkintNintm) {inti; Const intMoD =1000000007; LL sum=1;  for(i = n-m +1; I <= N; i++) {sum*=(LL) i; Sum%=MoD; } LL tmp=1;  for(i =2; I <= m; i++) TMP*= I, TMP%=MoD; Sum*=INV (TMP, MoD); Sum%=MoD; printf ("%i64d\n", sum);}intMain () {intN, M;  while(SCANF ("%d%d", &n, &m) = =2) {        if(M <N) {intTMP =m; M=N; N=tmp; } work (M+ N-4N2); }    return 0;}

hdu5698 Baidu Star 2016round2b the 3rd question

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.