51nod1119 机器人走方格 V2

终于学到了求组合数的正确姿势

//C(n+m-2,m-1)
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ll long long
int read(){
	int x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
	return x;
}
const int nmax=2e6+5;
const ll mod=1e9+7;
ll a[nmax];
ll pow(ll x,int n){
	ll ans=x;--n;
	while(n){
		if(n&1) ans=(ans*x)%mod;
		x=(x*x)%mod;n>>=1;
	}
	return ans;
}
int main(){
	int n=read(),m=read();a[0]=1;
	rep(i,1,n+m-2) a[i]=a[i-1]*i%mod;
	printf("%lld\n",a[n+m-2]*pow(a[n-1],mod-2)%mod*pow(a[m-1],mod-2)%mod);
	return 0;
}

  

基准时间限制:1 秒 空间限制:131072 KB 分值: 10  难度:2级算法题
 收藏
 关注
M * N的方格,一个机器人从左上走到右下,只能向右或向下走。有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 10^9 + 7的结果。
 
Input
第1行,2个数M,N,中间用空格隔开。(2 <= m,n <= 1000000)
Output
输出走法的数量 Mod 10^9 + 7。
Input示例
2 3
Output示例
3

转载于:https://www.cnblogs.com/fighting-to-the-end/p/5862663.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值