[Lucas 原理+逆元]BZOJ 4403——序列统计
来源:互联网 发布:广联达计价软件多少钱 编辑:程序博客网 时间:2024/05/16 06:25
题目描述
给定三个正整数N、L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量。
输出答案对10^6+3取模的结果。
解题思路
显然L,R的大小对答案没有影响,但是相对大小有影响,设
用隔板法可推出长度为n的方案数
于是总方案就是
通过
于是就可以得到总方案为
然后直接套用Lucas定理就可以了。
#include<cstdio>#define LL long longusing namespace std;const int maxn=1000010,tt=1000003;LL ji[maxn];int T,L,R,n;void work(){ji[0]=1;for (int i=1;i<maxn;i++) ji[i]=(ji[i-1]*i)%tt;}LL qsm(LL w,int b){ LL num=1; while(b>0){ if (b%2==1) num=num*w%tt; w=w*w%tt; b>>=1; } return num;}LL c(int x,int y){if (x>y) return 0;return ji[y]*qsm(ji[x]*ji[y-x]%tt,tt-2)%tt;}LL Q(int x,int y){LL num=1;while(y) num=num*c(x%tt,y%tt)%tt,x/=tt,y/=tt;return num;}int main(){ freopen("exam.in","r",stdin); freopen("exam.out","w",stdout); scanf("%d",&T); work(); while(T--){ scanf("%d%d%d",&n,&L,&R); printf("%lld\n",(Q(R-L+1,R-L+1+n)-1+tt)%tt); } return 0;}
阅读全文
0 0
- [Lucas 原理+逆元]BZOJ 4403——序列统计
- BZOJ 4403: 序列统计 Lucas
- 【BZOJ】4403 序列统计 Lucas
- BZOJ 4403 序列统计 Lucas定理
- BZOJ 4403: 序列统计|Lucas定理
- [BZOJ 4403]序列统计:Lucas定理
- [BZOJ]4403: 序列统计 Lucas定理
- 【BZOJ 4403】【推公式+Lucas定理】 序列统计
- BZOJ-4403 序列统计 组合数学 + Lucas定理
- BZOJ 4403: 序列统计 (组合数 Lucas 数论推导)
- bzoj 4403: 序列统计 lucas定理+组合数学
- 4403: 序列统计 组合数学+Lucas定理
- BZOJ4403 序列统计 [Lucas]
- bzoj 4403: 序列统计
- bzoj 2982: combination lucas定理+乘法逆元
- 【BZOJ4403】序列统计【Lucas定理】
- [BZOJ4403][Lucas定理]序列统计
- [bzoj4403]序列统计 Lucas定理
- Linux系统之虚拟机管理
- 素数对猜想
- 三人斗地主基础玩法
- Android 之 解决SVN Cleanup错误: Failed to run the WC DB work queue associated ……
- 使用Logistic回归进行分类(代码笔记)
- [Lucas 原理+逆元]BZOJ 4403——序列统计
- unity使用单例创建物体
- 玩转 Go Hack 之官方攻略 | 赛前指南
- 用 Go 搭建 Kubernetes Operators
- 毛剑:Bilibili 的 Go 服务实践(下篇)
- 一周 Go World 新鲜事[Asta 优选]
- 小红书在容器环境的CD实践
- 毛剑:Bilibili 的 Go 服务实践(上篇)
- 一周 Go World 新鲜事[Asta 优选]