P2265 roadside ditch

Topic background

LYQ city has a huge ditch network, can be approximated as a n * m rectangular grids, each grid point of the grid gates are installed, we will lower right corner of the gate of the ditch network to the upper left corner of the gate the path is called a flow.

Title Description

Now given length and width of the ditch network, seeking all the ditch network contains only the number of the left and upward movement of water.

Input Format

Input common line 1, comprising two integers n and m.

Output Format

Outputs a digital ans, i.e., the number of flow. Since the answer may be large, please answer the output result of the modulo 1,000,000,007.

Sample input and output

Input # 1
3 5
Output # 1
56

Description / Tips

Data for 30%, 1 ≤ m, n ≤ 10.

Data for 50%, 1 ≤ m, n ≤ 1,000.

For 80% of data, 1 ≤ m, n ≤ 50,000.

To 100% of the data, 1 ≤ m, n ≤ 1,000,000.

 

Lucas Theorem look

 

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
inline ll pow(ll a,ll n,ll p)
{
    ll ans=1;
    while(n)
    {
        if(n&1)
        ans=ans*a%p;
        a=a*a%p;
        n>>=1;
    }
    return ans;
} 
inline ll fm(ll a)
{
    return pow(a,mod-2,mod);
}
inline ll jc(ll x)
{
    ll ans=1;
    for(int i=2;i<=x;i++)
    {
        ans*=i;
        ans%=mod;
    }
    return ans;
}
ll c(ll a,ll b)
{
    return (((jc(b)%mod*fm(jc(a))%mod)%mod)*fm(jc(b-a))%mod);
}
int main()
{
    int n,m;
    cin>>n>>m;
    cout<<c(n,n+m);
}
 

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11518055.html