51nod1486 Big Walk lattice

Source: Internet
Author: User
Tags time limit

Actual Source: codeforces559c. Gerald and Giant Chess

Base time limit: 1 seconds space limit: 131072 KB score: 160 Difficulty: 6-level algorithm problem
There is an H-row W-column of the chessboard, there are some lattice can not walk , can only go down or to the right, now requires to go from the upper left to the lower right corner of the program number.
Input
A single set of test data.
The first line has three integers h, W, N (1≤h, w≤10^5, 1≤n≤2000), which represent the rows and columns of the chessboard, and the number of squares that cannot be walked.
The next n lines describe the lattice, and line I has two integer ri, ci (1≤ri≤h, 1≤ci≤w), representing the row and column where the lattice resides.
Enter guaranteed start and end points there will be no way to go.
Output
Output answers to 1000000007 of the results of the remainder.
Input example
3 4 2
2 2
2 3
Output example
2

(as Codeforces the original title, the can not go to the lattice called Black bar)
If there is no such black dots (n=0), this is a classic problem, we can consider the DP solution f[i][j]=f[i−1][j]+f[i][j−1] f[ I][J]=F[I-1][J]+F[I][J-1], careful observation of the transfer equation, we can find it is similar to the Yang Hui triangle equation, and we have the F-f array of matrix rotation 45 degrees can be found that it is part of the Yang Hui Triangle, In fact, for n rows of M-column matrices (where n rows of M-columns refer to n*m), the number of schemes from top left to bottom right is cn−1n+m−2 c_{n+m-2}^{n-1}. N row m column, can only go down or to the right, then we have to go down n-1 times, to the right m-1 times, then we go from the left up to the lower right of the path can be represented by the n-1 down and m-1 times to the right of the sequence, and this sequence of the order is irrelevant, As long as the n-1 times down and m-1 times to the right we can and will go to the lower right corner, so this is a combinatorial problem, that is, cn−1n+m−2=cm−1n+m−2 c_{n+m-2}^{n-1}=c_{n+m-2}^{m-1}
So what do we do with the black dots now? Consider the idea of complementary set and the principle of tolerance. Then the final answer = way[arbitrarily walk]−way[through at least one black point]+way[through at least two black spots]−way[through at least three black spots] ... way[arbitrarily walk]-way[by at least one black spot]+way[via at least three black spots]-way[through at least two black spots] ... (where way[] way[] represents the number of scenarios). And n=2000 obviously can't enumerate the collection, how to do it. We need the particularity of the subject: There are dependencies and stages between different objects. That is to say, we elect at least two black spots based on the first black point, consider which black spots the black spot can reach to get, and so on. Since there is a stage we can consider DP, first by the x-coordinate and the y-coordinate ascending order, F[i] f[i] represents from the upper left to the first point in the middle without any black spots of the scheme number, transfer equation F[i]=calc (xi−1,yi−1) −f[j

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.