c语言sscanf函数的用法是什么
257
2022-08-30
Codeforces 560 E. Gerald and Giant Chess (dp,组合数学)
Description
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we’ll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of giant chess against his friend Pollard. Gerald has almost won, and the only thing he needs to win is to bring the pawn from the upper left corner of the board, where it is now standing, to the lower right corner. Gerald is so confident of victory that he became interested, in how many ways can he win?The pawn, which Gerald has got left can go in two ways: one cell down or one cell to the right. In addition, it can not go to the black cells, otherwise the Gerald still loses. There are no other pawns or pieces left on the field, so that, according to the rules of giant chess Gerald moves his pawn until the game is over, and Pollard is just watching this process.
Input
The first line of the input contains three integers: h, w, n — the sides of the board and the number of black cells (1 ≤ h, w ≤ 10^5, 1 ≤ n ≤ 2000).Next n lines contain the description of black cells. The i-th of these lines contains numbers ri, ci (1 ≤ ri ≤ h, 1 ≤ ci ≤ w) — the number of the row and column of the i-th cell.It is guaranteed that the upper left and lower right cell are white and all cells in the description are distinct.
Output
Print a single line — the remainder of the number of ways to move Gerald’s pawn from the upper left to the lower right corner modulo 10^9 + 7.
Examples input
3 4 22 22 3
Examples output
2
题意
在一个 h×w
思路
首先对所有坏点按照 x 作为第一键值, y
dp[i] 代表从 (1,1) 走到第 i
显然:
dp[0]=(x0+y0−2x0−1)
dp[i]=(xi+yi−2xi−1)−∑j=0i−1(xi−xj+yi−yjxi−xj)×dp[j]
其中 j 为我们枚举出现在 i
仔细想想我们还可以发现,将 (h,w) 当作坏点那它一定是最后一个,此时的结果为 dp[last]
AC 代码
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~