zoukankan      html  css  js  c++  java
  • [BZOJ4403]序列统计

    题意:给定三个正整数N、L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量。输出答案对10^6+3取模的结果。
    我的数学好差啊。。。

    推式子见:http://www.cnblogs.com/Var123/p/5546290.html

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<ctime>
    #include<queue>
    #include<map>
    #include<set>
    #include<vector>
    typedef long long LL;
    using namespace std;
    const LL p=1000003;
    LL T,n,R,L,fac[p+1];
    LL read() {LL d=0,f=1; char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') d=(d<<3)+(d<<1)+c-48,c=getchar(); return d*f;}
    void judge(){freopen(".in","r",stdin); freopen(".out","w",stdout);}
    LL quickmi(LL a,LL b)
    {
        LL res=1;
        while (b)
        {
            if (b&1) res=res*a%p;
            a=a*a%p; b>>=1;
        }
        return res;
    }
    LL C(LL n,LL m)
    {
        if (n<m) return 0;
        if (n==m) return 1;
        return fac[n]*quickmi(fac[m]*fac[n-m]%p,p-2)%p;
    }
    LL lucas(LL n,LL m)
    {
        LL res=1;
        while (n&&m&&res)
        {
            res=res*C(n%p,m%p)%p;
            n/=p; m/=p;
        }
        return res;
    }
    int main()
    {
        //judge();
        fac[0]=1;
        for (int i=1;i<=p;i++) fac[i]=fac[i-1]*i%p;
        T=read();
        while (T--)
        {
            n=read(); L=read(); R=read();
            LL ans=lucas(n+R-L+1,R-L+1);
            printf("%lld
    ",(ans-1+p)%p);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Linux 基础命令3 shell
    Django 的学习(2) 从adminuser到配置
    Linux巨好用的
    常见任务&基本工具 1 软件包管理
    java学习补全 1
    基础命令1
    java 5 绘图GUI
    Open GL与OpenGLES
    NDK 安装步骤
    转:为什么要有handler机制?
  • 原文地址:https://www.cnblogs.com/lujiaju6555/p/6795935.html
Copyright © 2011-2022 走看看