zoukankan      html  css  js  c++  java
  • 51nod 1120 机器人走方格 V3

    N * N的方格,从左上到右下画一条线。一个机器人从左上走到右下,只能向右或向下走。
    并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法?
    由于方法数量可能很大,只需要输出Mod 10007的结果。
     
    Input
    输入一个数N(2 <= N <= 10^9)。
    Output
    输出走法的数量 Mod 10007。
    Input示例
    4
    Output示例
    10
    ————————————————————————————
    这题是裸的卡特兰数 不过因为mod比2*n小 所以要加上lucas 然后就没辣
    详情请自行百度卡特兰数
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define LL long long
    const int mod=10007,M=2e4+7;
    int read(){
        int ans=0,f=1,c=getchar();
        while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
        while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
        return ans*f;
    }
    int n,m;
    LL w[M],b[M];
    LL pmod(LL a,LL b){
        LL ans=1;
        while(b){
            if(b&1) ans=ans*a%mod;
            b>>=1; a=a*a%mod;
        }return ans;
    }
    void prepare(){
        int mx=mod-1;
        w[0]=1; for(int i=1;i<=mx;i++) w[i]=w[i-1]*i%mod;
        b[mx]=pmod(w[mx],mod-2);
        for(int i=mx;i;i--) b[i-1]=b[i]*i%mod;
    }
    LL C(LL n,LL m){
        if(n<m) return 0;
        if(n<mod) return w[n]*b[m]%mod*b[n-m]%mod; 
        return C(n/mod,m/mod)*C(n%mod,m%mod);//C(n%mod,m%mod)=w[n%mod]*b[m%mod]%mod*b[n%mod-m%mod]%mod
    }
    int main(){
        n=read()-1; prepare();
        printf("%lld
    ",(2*(C(2*n,n)-C(2*n,n-1))%mod+mod)%mod);
        return 0;
    }
    View Code
     
  • 相关阅读:
    Oracle11g 修改内存配置
    七.从按键输入到GPIO通用驱动
    三.C语言版本的LED驱动试验
    五.NXP恩智浦官方SDK使用
    前期准备——1.Makefile的使用及基本语法
    八.主频及时钟配置
    四.指针形式对寄存器进行操作(类似STM32效果)
    二.I.MX6U的启动方式
    六.蜂鸣器驱动
    六.项目的BSP工程管理
  • 原文地址:https://www.cnblogs.com/lyzuikeai/p/7747777.html
Copyright © 2011-2022 走看看