6451:Iroha and a Grid(组合数+思维)

6451: Iroha and a Grid

时间限制: 1 Sec   内存限制: 128 MB
提交: 226   解决: 67
[ 提交][ 状态][ 讨论版][命题人: admin]

题目描述

We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 109+7.

Constraints
1≤H,W≤100,000
1≤A<H
1≤B<W

输入

The input is given from Standard Input in the following format:

H W A B

输出

Print the number of ways she can travel to the bottom-right cell, modulo 109+7.

样例输入

2 3 1 1

样例输出

2

提示

We have a 2×3 grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".

分为两部分求解
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<algorithm>
#define mod 1000000007
using namespace std;
long long jie[1000005];
long long qpow(long long a, long long b)
{
    long long ans=1;
    while(b)
    {
        if(b%2)
            ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans%mod;
}
void f()
{
    jie[0]=1;
    for(int i=1;i<1000001;i++)
        jie[i]=(jie[i-1]*i)%mod;
}
long long zuhe(long long n, long long m)
{
    long long a=jie[n];
    long long b=(jie[m]*jie[n-m])%mod;
    return (a*qpow(b, mod-2))%mod;
}
int main()
{
    f();
    long long h, w, a, b, ans=0;
    scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
    for(int i=b+1;i<=w;i++)
    {
        long long temp=(zuhe(h-a+i-2, h-a-1)%mod*zuhe(w-i+a-1, w-i)%mod)%mod;
        ans=(ans+temp)%mod;
    }
    printf("%lld\n", ans);
    return 0;
}
 
/**************************************************************
    Problem: 6451
    User: ldu_reserver201701
    Language: C++
    Result: 正确
    Time:112 ms
    Memory:8904 kb
****************************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hhjian6666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值