• 51nod1627 瞬间移动


    打表可以看出来是组合数。。。妈呀为什么弄成n+m-4,n-1,m-3就错啊。。。 

    //打表可以看出来是组合数。。。妈呀为什么弄成n+m-4,n-1,m-3就错啊。。。  
    #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 clr(x,c) memset(x,c,sizeof(x))
    #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 ll mod=1e9+7;
    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;
    }
    ll a[200005];
    int main(){
    	int n=read(),m=read();
    	if(m==2||n==2){
    		printf("1
    ");return 0;
    	}
    	--n;--m;
    	if(n>m) swap(n,m);
    	a[0]=1;
    	rep(i,1,n+m) a[i]=a[i-1]*i%mod;
    	printf("%lld
    ",a[n+m-2]*pow(a[n-1],mod-2)%mod*pow(a[m-1],mod-2)%mod);
    	return 0;
    }
    

      

    基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
     收藏
     关注

    有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右下方格子,并瞬移过去(如从下图中的红色格子能直接瞬移到蓝色格子),求到第n行第m列的格子有几种方案,答案对1000000007取模。

    Input
    单组测试数据。
    两个整数n,m(2<=n,m<=100000)
    Output
    一个整数表示答案。
    Input示例
    4 5
    Output示例
    10
  • 相关阅读:
    MINA的session.close
    Maven构建灵活配置文件
    函数的凹凸性
    幂函数习题
    2017全国卷1文科第9题高考真题的解法
    指数函数习题
    三角形的四心的向量表示
    进退中体会数学运算和数学策略
    函数f(x+1)和f(x-1)的奇偶性
    函数的奇偶性周期性习题
  • 原文地址:https://www.cnblogs.com/fighting-to-the-end/p/5862682.html
Copyright © 2020-2023  润新知