bzoj4403 序列统计
来源:互联网 发布:淘宝面膜销量排行榜 编辑:程序博客网 时间:2024/06/10 04:18
题目
本人太菜,无法直接推公式,来来来,我们先写个暴力,简单吧。
之后,根据敏锐的观察力,发现了规律:ans=C(m+n,m)-1,m=r-l+1。
注意要用到Lucas,不然,嘿嘿嘿。。。
#include<bits/stdc++.h>#define mod 1000003#define ll long longusing namespace std;ll n,m,r,l,T;ll fac[mod+1],inv[mod+1],fac_inv[mod+1];inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline ll read(){ ll x=0,b=1; char c=nc(); for(;!(c<='9'&&c>='0');c=nc())if(c=='-')b=-1; for(;c<='9'&&c>='0';c=nc())x=x*10+c-'0'; return x*b;}inline ll C(ll n,ll m){ if(n<m)return 0; return (ll)(((fac[n]*fac_inv[m])%mod)*fac_inv[n-m])%mod;}inline ll Lucas(ll n,ll m){ if(n==0||m==0)return 1; return (ll)Lucas(n/mod,m/mod)*C(n%mod,m%mod)%mod;}inline void init(){ fac[0]=1; for(ll i=1;i<=mod;i++)fac[i]=(ll)fac[i-1]*i%mod; inv[1]=1; for(ll i=2;i<=mod;i++)inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod; fac_inv[0]=1; for(ll i=1;i<=mod;i++)fac_inv[i]=fac_inv[i-1]*inv[i]%mod;}int main(){ //freopen("in.txt","r",stdin); init(); T=read(); while(T--) { n=read(),l=read(),r=read(); m=r-l+1; printf("%d\n",(Lucas(n+m,m)-1+mod)%mod); } return 0;}
日常数学。。。。。慢爆了
阅读全文
0 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[序列统计]题解
- bzoj1433 [ZJOI2009]假期的宿舍
- bzoj1934 [Shoi2007]Vote 善意的投票
- bzoj2127 happiness
- 精度保证下的新型深度网络压缩框架
- bzoj3192 [JLOI2013]删除物品
- bzoj4403 序列统计
- bzoj4562 [Haoi2016]食物链
- bzoj4993 [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj4994 [Usaco2017 Feb]Why Did the Cow Cross the Road III
- Oracle 学习笔记 图解深入剖析一个事务的操作流程
- 控制台打印空心菱形
- SSH整合中sessionFactory创建失败问题
- 京东面试题分享
- 新型农业经营主体