time limit:1000ms single point time limit:1000ms memory limit:256MB
Description
Given a n*m grid, the upper-left corner (1, 1), the lower-right corner (n, M).
Small w in (I, j), he will select two different but orthogonal directions from "top left down right" in four directions, and then he can only walk along those two directions until he walks out of the grid.
Little W wants to know how many different ways to go.
The two walk differs when and only if the set of the passed lattice is different.
input
The input contains multiple sets of data.
Each group of data is a row of four integers n, m, I, J. (1 <= i <= n <=, 1 <= J <= M <= 100)
Output
For each set of data, the output is an integer representing the number of scenarios, and the answer is modulo 1000000007.
Sample Explanation
Either way, cover a grid or cover two grid.
-
- Sample input
-
- 2 1 1 1
-
- Sample output
-
- 2
Title Link: http://hihocoder.com/problemset/problem/1191
Title Analysis: The problem of the number of walking programs in this box, any two blocks (x1, y1), (x2, y2) walk between the program number is C[abs (x1-x2)][abs (X1-X2) + ABS (Y1-Y2)],C is the combination number, then for this problem, I ask for IS (I,J) This point to the four-sided scheme number and, enumerate the boundary with the above formula to calculate it.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;int const MAX = 205;int Const MOD = 1e9 + 7;int c[max][max];void Pre () { c[0][0] = 1; for (int i = 1; i <=; i++) { c[i][0] = 1; for (int j = 1; J <=, J + +) c[i][j] = (c[i-1][j]% mod + c[i-1][j-1]% mod)% mod; } int main () { int n, M, I, J; Pre (); while (scanf ("%d%d%d", &n, &m, &i, &j)! = EOF) { int ans = 0; for (int x = 1; <= n; x + +) {for (int y = 1; y <= m; y++) { if (x = = 1 | | x = = N | | y = = 1 | | y = = m) { int xx = ABS (x-i); int yy = ABS (Y-J); Ans = (ans% mod + c[xx + yy][xx]% mod)% mod; }} printf ("%d\n", ans);} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hihocoder 1191 Small w with grid (combination number)