zoukankan      html  css  js  c++  java
  • いろはちゃんとマス目 / Iroha and a Grid AtCoder

    Problem Statement

     

    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

    Input

     

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

    H W A B
    

    Output

     

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

    Sample Input 1

     

    2 3 1 1
    

    Sample Output 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".

    Sample Input 2

     

    10 7 3 4
    

    Sample Output 2

     

    3570
    

    There are 12 forbidden cells.

    Sample Input 3

     

    100000 100000 99999 99999
    

    Sample Output 3

     

    1
    

    Sample Input 4

     

    100000 100000 44444 55555
    

    Sample Output 4

     

    738162020
    //44m36sAK!!!
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <ctime>
    #include <map>
    #include <set>
    #include <queue>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.141592653589793238462
    #define INF 0x3f3f3f3f3f
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    ll gcd(ll a,ll b){
        return b?gcd(b,a%b):a;
    }
    bool cmp(int x,int y)
    {
        return x>y;
    }
    const int N=2e5+20;
    const ll mod=1e9+7;
    ll f[N],n,m,A,B;
    ll powmod(ll x,ll n)
    {
        ll s=1;
        while(n){
            if(n&1)
                s=(s*x)%mod;
            x=(x*x)%mod;
            n>>=1;
        }
        return s;
    }
    ll C(ll n,ll m)
    {
        ll a=f[n];
        ll b=(f[m]*f[n-m])%mod;
        return (a*powmod(b,mod-2))%mod;
    }
    int main()
    {
        f[0]=1;
        for(ll i=1;i<N;i++)
            f[i]=(f[i-1]*i)%mod;
        while(cin>>n>>m>>A>>B){
            ll res=0;
            for(ll i=B+1;i<=m;i++){
                ll tmp=(C(i-1+n-A-1,n-A-1)*C(m-i+A-1,m-i))%mod;
                res=(res+tmp)%mod;
            }
            cout<<res<<endl;
        }
        return 0;
    }
  • 相关阅读:
    mysql查找有某列但没有此列索引的表
    mysql找到所有索引
    mysq在某一刻同时获取主从库的位置点
    新书《深入应用C++11:代码优化与工程级应用》出版,感谢支持
    c++11实现一个简单的lexical_cast
    应该用bind+function取代虚函数吗?
    《深入应用C++11:代码优化与工程级应用》开始发售
    一个更好的C++序列化/反序列化库Kapok
    C++技术沙龙主要内容
    C++11模版元编程
  • 原文地址:https://www.cnblogs.com/upstart/p/8982402.html
Copyright © 2011-2022 走看看