• hdu-5698 瞬间移动(数论+快速幂)


    题目链接:

    瞬间移动

    Problem Description
     

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

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

     
    Input
     

    多组测试数据。

    两个整数n,m(2<= n,m<=100000)

    Output
     

    一个整数表示答案

    Sample Input
     
    4 5
     
    Sample Output
     
    10

    题意:



    思路:

    跟那个只能向下和向右走有多少种方案差不多,最后的结果就是一个那个是同一个组合数,用快速幂幂和费马小定理搞;

    AC代码
    #include <bits/stdc++.h>
    /*
    #include <iostream>
    #include <queue>
    #include <cmath>
    #include <map>
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    */
    using namespace std;
    #define Riep(n) for(int i=1;i<=n;i++)
    #define Riop(n) for(int i=0;i<n;i++)
    #define Rjep(n) for(int j=1;j<=n;j++)
    #define Rjop(n) for(int j=0;j<n;j++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    typedef long long LL;
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=0x3f3f3f3f;
    const int N=2e5+25;
    int n,m;
    LL dp[2*N];
    int Init()
    {
        dp[1]=1;
        for(int i=2;i<2*N;i++)
        {
            dp[i]=dp[i-1]*(LL)i;
            dp[i]%=mod;
        }
    }
    LL fastpow(LL x,LL y)
    {
        LL ans=1,base=x;
        while(y)
        {
            if(y&1)
            {
                ans*=base;
                ans%=mod;
            }
            base*=base;
            base%=mod;
            y>>=1;
        }
        return ans;
    }
    int main()
    {
            Init();
           while(scanf("%d%d",&n,&m)!=EOF)
           {
               if(n==2||m==2)cout<<"1"<<"
    ";
               else
               {
               n-=2;
               m-=2;
               LL x=dp[n],y=dp[m];
               LL ans=dp[n+m]*fastpow(x*y%mod,mod-2)%mod;
               cout<<ans<<"
    ";
               }
           }
    
    
        return 0;
    }



  • 相关阅读:
    基于Html5的爱情主题网站–表白神器
    一个基于WebGL的仿真3D水池有逼真的水波纹效果
    一些纯css3写的公司logo
    IIS、SQL SERVER和VS的安装顺序
    SQL Server 2008 收缩日志 清空删除大日志文件
    判断SqlConnection连接是否关闭
    正则
    C# MD5加密字符串
    sqlServer MD5
    sqlserver 连接数
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5524406.html
Copyright © 2020-2023  润新知