ASTAR2016 ROUND2B 1003 Instantaneous movement

Source: Internet
Author: User

http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=702&pid=1003

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 (strictly in the current position of the lower right), and teleport past (such as the red lattice from the direct blink to the blue lattice), the nth row m column of the lattice has several options, Answer to 1000000007 modulo.

Input

Multiple sets of test data.

Two integers of n,m (2≤n,m≤100000).

Sample Input
4 5
Sample Output
10
Solution

Assuming that altogether moved R-Step, step-i-x[i], longitudinal walk y[i], then there is x[1] + ... + x[r] = m-1; Y[1] + ... + y[r] = n-1. As long as the number of such an array can be calculated, the test of a few s divided into R can be the same positive integer, using the model of the Board can be found to divide the number is C (s-1, r-1). So for the current R, the total number of paths is C (n-2, r-1) * C (m-2, r-1).

Enumeration R takes 1 to min (n-1, m-1) and can pass this question.

If you look at it in a different way, it's easier to first list the table with the number of scenarios for the previous 5 rows and 5 columns:


1 0 0) 0 0
0 1 1) 1 1
0 1 2) 3 4
0 1 3) 6 10
0 1 4) 10 20

It is easy to infer:

But it is inconvenient to calculate, we consider simplification, f (n, m) = f (n-1,m) + f (n,m-1) + f (n-1,m-1)-T. We use T to represent the repeating portion of F (n-1,m) and F (n,m-1). It is not difficult to see that this repeating part is F (n-1,m-1), so we have f (n, m) = f (n-1,m) + f (n,m-1).

By discovering this, you can see that the answer is from (2,2) to the "No Fallback Path" (n, m) number, which is C (N-2 + m-2, n-2).

ASTAR2016 ROUND2B 1003 Instantaneous movement

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.