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;
    }
  • 相关阅读:
    关于自学的又一点思考
    hdu 1176 免费馅饼
    AS400 Sequel View报表学习笔记 (一)
    AS400 QUERY中的Unmatched records探讨。
    AS400 SDA development Note (1)
    关于Actionscript 3.0中KeyboardEvent的调试需注意的问题
    iPhone开发的常用的API函数库
    Cocos2DiPhone编程中按钮的设置(MenueItem类系的介绍)
    维基网上公布的世界上的一些算法<希望能对寻找算法的一些朋友有帮助>
    关于面向对象编程与面向过程编程的介绍与解释
  • 原文地址:https://www.cnblogs.com/upstart/p/8982402.html
Copyright © 2011-2022 走看看