【BZOJ4403】序列统计
来源:互联网 发布:python 下划线用法 编辑:程序博客网 时间:2024/06/10 05:59
Description
给定三个正整数N、L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量。输出答案对10^6+3取模的结果。
Input
输入第一行包含一个整数T,表示数据组数。第2到第T+1行每行包含三个整数N、L和R,N、L和R的意义如题所述。
Output
输出包含T行,每行有一个数字,表示你所求出的答案对106+3取模的结果。
Sample Input
21 4 52 4 5
Sample Output
25
HINT
提示
【样例说明】满足条件的2个序列为[4]和[5]。
【数据规模和约定】对于100%的数据,1≤N,L,R≤10^9,1≤T≤100,输入数据保证L≤R。
Source
By yts1999
答案是C(r-l+1+n,n)-1
Lucas一下
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define GET (ch>='0'&&ch<='9')#define P 1000003#define LL long longusing namespace std;int T,n,l,r;int fac[P+10]={1};int Pow(int a,int b){ int ret=1;a%=P; for (;b;a=(LL)a*a%P,b>>=1) if (b&1) ret=(LL)ret*a%P; return ret;}void in(int &x){ char ch=getchar();x=0; while (!GET) ch=getchar(); while (GET) x=x*10+ch-'0',ch=getchar();}int C(int n,int m){ return n<m?0:(int)((LL)fac[n]*Pow(fac[m],P-2)%P*Pow(fac[n-m],P-2)%P);}int lucas(int n,int m){ int ret=1; for (;n||m;n/=P,m/=P) ret=(LL)ret*C(n%P,m%P)%P; return ret;}int main(){ for (int i=1;i<=P;i++) fac[i]=(LL)fac[i-1]*i%P; for (in(T);T;T--) { in(n);in(l);in(r); printf("%d\n",(lucas(r-l+1+n,n)-1+P)%P); }}
1 0
- bzoj4403 序列统计 组合
- 【BZOJ4403】序列统计
- BZOJ4403: 序列统计
- BZOJ4403 序列统计
- bzoj4403: 序列统计
- bzoj4403 序列统计
- BZOJ4403: 序列统计
- bzoj4403 序列统计
- BZOJ4403 序列统计 [Lucas]
- BZOJ4403 序列统计
- 【BZOJ4403】序列统计【Lucas定理】
- [BZOJ4403][Lucas定理]序列统计
- [bzoj4403]序列统计 Lucas定理
- 【lucas定理】BZOJ4403 序列统计
- Bzoj4403序列统计:Lucas初探,组合数学
- 【BZOJ4403】【lucas】【组合数】序列统计 题解
- bzoj4403 序列统计 ( 组合数学 + lucas )
- 【Lucas定理】BZOJ4403[序列统计]题解
- Web app root system property already set to different value 错误原因及解决
- 工作心态
- div的margin、border、padding的关联
- Qt5与ARM交叉编译环境搭建
- Java 多态性 理解
- 【BZOJ4403】序列统计
- 让自己的开源项目支持CocoaPods
- Exec'ing Processes
- 【ROS学习】(五)ROS消息传递——自定义消息
- css设置尖角按钮
- linux实战(四)----写入文件----实例解析
- windows下利用OpenVPN搭建VPN服务器
- Spring 4.2框架中注释驱动的事件监听器详解
- TBB之parallel_reduce