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

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

    本文作者:ljh2000
    作者博客:http://www.cnblogs.com/ljh2000-jump/
    转载请注明出处,侵权必究,保留最终解释权!

    题目链接:BZOJ4403

    正解:$Lucas$定理+组合数学

    解题报告:

      考虑这类不降的问题,我们通常把第$i$个数$+i$变成求升序序列问题。

      那么权值范围变成了$[l+1,r+n]$,一共$r-l+n$个数,我们要选$i$个数的话就是$C_{r-l+i}^{i}$。

      显然答案就是对它求和,简化之后式子变成了$C_{n+R-L+1}^{R-L+1}-1$。

    //It is made by ljh2000
    //有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <ctime>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <string>
    #include <complex>
    #include <bitset>
    using namespace std;
    typedef long long LL;
    typedef long double LB;
    const double pi = acos(-1);
    const int mod = 1000003;
    int n,len,L,R,jie[mod+12],nj[mod+12];
    inline int fast_pow(int x,int y){ int r=1; while(y>0) { if(y&1) r=1LL*r*x%mod; x=1LL*x*x%mod; y>>=1; } return r; }
    inline int C(int n,int m){ if(n<m) return 0; return 1LL*jie[n]*nj[m]%mod*nj[n-m]%mod; }
    inline int getint(){
        int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
        if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
    }
    
    inline void Init(){
    	jie[0]=nj[0]=1; for(int i=1;i<mod;i++) jie[i]=1LL*jie[i-1]*i%mod;
    	nj[mod-1]=fast_pow(jie[mod-1],mod-2); for(int i=mod-2;i>=1;i--) nj[i]=1LL*nj[i+1]*(i+1)%mod;
    }
    
    inline int Lucas(int n,int m){
    	if(n<m) return 0; if(m==0) return 1;
    	if(n<mod && m<mod) return C(n,m);
    	return 1LL*Lucas(n/mod,m/mod)*C(n%mod,m%mod)%mod;
    }
    
    inline void work(){
    	Init();	int T=getint();
    	while(T--) {
    		n=getint(); L=getint(); R=getint();
    		len=R-L+1;
    		printf("%d
    ",(Lucas(len+n,n)-1+mod)%mod);
    	}
    }
    
    int main()
    {
    #ifndef ONLINE_JUDGE
    	freopen("4403.in","r",stdin);
    	freopen("4403.out","w",stdout);
    #endif
        work();
        return 0;
    }
    //有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。
    

      

  • 相关阅读:
    unity3d 随机生成地形之随机山脉
    unity3d ppsspp模拟器中的post processing shader在unity中使用
    unity3d shader之实时室外光线散射(大气散射)渲染
    Unity3d 游戏中的实时降噪-对Square Enix文档的研究与实现
    Unity3d 获取屏幕depth与normal
    unity3d Hair real time rendering 真实头发实时渲染
    java.net.URL类
    Springboot定时任务
    Base64编码
    ShiroUtil 对密码进行加密
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/6628488.html
Copyright © 2011-2022 走看看