bzoj 4403: 序列统计
来源:互联网 发布:淘宝购买流量怎么退款 编辑:程序博客网 时间:2024/06/05 10:46
4403: 序列统计
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 655 Solved: 322
[Submit][Status][Discuss]
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
【分析】
借鉴popoqqq的代码
算是lucas定理的模板题了…
lucas(n,m,p)=C(n%p,m%p) * lucas(n/p,m/p,p) % p
【代码】
#include<iostream>#include<cstring>#include<cstdio>#define ll long long#define M(a) memset(a,0,sizeof a)#define fo(i,j,k) for(i=j;i<=k;i++)int n,m,l,r;ll fac[1000005],inv[1000005];const int mod=1e6+3;inline void init(){ int i,j; for(fac[0]=1,i=1;i<mod;i++) fac[i]=fac[i-1]*i%mod; for(inv[1]=1,i=2;i<mod;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod; for(inv[0]=1,i=1;i<mod;i++) (inv[i]*=inv[i-1])%=mod;}inline ll C(int n,int m){ if(n<m) return 0; if(n<mod && m<mod) return fac[n]*inv[m]%mod*inv[n-m]%mod; return C(n/mod,m/mod)*C(n%mod,m%mod)%mod;}int main(){ int i,j,T; init(); scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&l,&r); m=r-l+1; printf("%d\n",(C(n+m,m)-1+mod)%mod); } return 0;}/*21 4 52 4 5*/
1 0
- bzoj 4403: 序列统计
- BZOJ 4403: 序列统计 Lucas
- 【BZOJ】4403 序列统计 Lucas
- BZOJ 4403 序列统计 Lucas定理
- BZOJ 4403: 序列统计|Lucas定理
- [组合数学] BZOJ 4403 序列统计
- [BZOJ 4403]序列统计:Lucas定理
- [BZOJ]4403: 序列统计 Lucas定理
- BZOJ P4403 序列统计
- BZOJ 3992 SDOI2015 序列统计
- BZOJ 3992 [SDOI2015]序列统计
- 【BZOJ 4403】【推公式+Lucas定理】 序列统计
- BZOJ-4403 序列统计 组合数学 + Lucas定理
- BZOJ 4403: 序列统计 (组合数 Lucas 数论推导)
- bzoj 4403: 序列统计 lucas定理+组合数学
- [Lucas 原理+逆元]BZOJ 4403——序列统计
- BZOJ 3992 [SDOI2015]序列统计 NTT
- bzoj 3992: [SDOI2015]序列统计 NTT
- PHP 活动人选抽奖示例代码
- Homework 1-1
- CMake学习笔记(一)——CMake官网教程
- Unity AssetBundles-Browser【官方分享】
- 图像小波变换的matlab实现
- bzoj 4403: 序列统计
- Easy 17 Climbing Stairs(70)
- 光立方制作清单
- maven管理jar包的一些问题小结
- 百度编辑器 单独开发图片上传功能
- Java-多线程
- wordpress 插件 easy video player https://wordpress.org/plugins/easy-video-player/
- IDEA远程调试Hadoop步骤及出错解决整理
- C++内联函数