Hihocoder 1191 Small w with grid (combination number)

Source: Internet
Author: User


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)

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.