zoukankan      html  css  js  c++  java
  • 2016"百度之星"

    瞬间移动

     
     Accepts: 1018
     
     Submissions: 3620
     Time Limit: 4000/2000 MS (Java/Others)
     
     Memory Limit: 65536/65536 K (Java/Others)
    Problem Description

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

    http://acm.hdu.edu.cn/data/images/C702-1003-1.jpg

    Input

    多组测试数据。

    两个整数n,m(2leq n,mleq 100000)n,m(2n,m100000)

    Output

    一个整数表示答案

    Sample Input
    4 5
    Sample Output
    10
    思路:ans=C(n+m-4,n-2);
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define mod 1000000007
    #define inf 999999999
    #define pi 4*atan(1)
    //#pragma comment(linker, "/STACK:102400000,102400000")
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF ) return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    void extend_Euclid(ll a, ll b, ll &x, ll &y)
    {
        if(b == 0)
        {
            x = 1;
            y = 0;
            return;
        }
        extend_Euclid(b, a % b, x, y);
        ll tmp = x;
        x = y;
        y = tmp - (a / b) * y;
    }
    ll combine1(ll n,ll m) //计算组合数C(n,m)
    {
        ll sum=1; //线性计算
        for(ll i=1,j=n;i<=m;i++,j--)
        {
            sum*=j;
            sum%=mod;
            ll x,y;
            extend_Euclid(i,mod,x,y);
            sum*=(x%mod+mod)%mod;
            sum%=mod;
        }
        return sum;
    }
    int main()
    {
        ll x,y,z,i,t;
        while(~scanf("%I64d%I64d",&x,&y))
        {
            ll n,k;
            ll ans=0;
            k=x-2;
            n=(x+y)-4;
            ans=combine1(n,k);
            printf("%I64d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    【数据大屏设计】有点意思
    MySQL环境搭建
    关于MySQL数据库
    zip-gzip-bzip2_压缩文件
    Linux的链接文件-ln命令
    电脑为什么越用越慢
    按下开机键,计算机背后的故事
    Windows最全快捷键
    环境搭建-VMware安装系统
    wee hours
  • 原文地址:https://www.cnblogs.com/jhz033/p/5517081.html
Copyright © 2011-2022 走看看