[BZOJ4403]序列统计
生活随笔
收集整理的這篇文章主要介紹了
[BZOJ4403]序列统计
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題意:給定三個(gè)正整數(shù)N、L和R,統(tǒng)計(jì)長度在1到N之間,元素大小都在L到R之間的單調(diào)不降序列的數(shù)量。輸出答案對(duì)10^6+3取模的結(jié)果。
我的數(shù)學(xué)好差啊。。。
推式子見:http://www.cnblogs.com/Var123/p/5546290.html
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm> #include<iostream> #include<string> #include<ctime> #include<queue> #include<map> #include<set> #include<vector> typedef long long LL; using namespace std; const LL p=1000003; LL T,n,R,L,fac[p+1]; LL read() {LL d=0,f=1; char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();} while (c>='0'&&c<='9') d=(d<<3)+(d<<1)+c-48,c=getchar(); return d*f;} void judge(){freopen(".in","r",stdin); freopen(".out","w",stdout);} LL quickmi(LL a,LL b) {LL res=1;while (b){if (b&1) res=res*a%p;a=a*a%p; b>>=1;}return res; } LL C(LL n,LL m) {if (n<m) return 0;if (n==m) return 1;return fac[n]*quickmi(fac[m]*fac[n-m]%p,p-2)%p; } LL lucas(LL n,LL m) {LL res=1;while (n&&m&&res){res=res*C(n%p,m%p)%p;n/=p; m/=p;}return res; } int main() {//judge();fac[0]=1;for (int i=1;i<=p;i++) fac[i]=fac[i-1]*i%p;T=read();while (T--){n=read(); L=read(); R=read();LL ans=lucas(n+R-L+1,R-L+1);printf("%lld\n",(ans-1+p)%p);}return 0; } View Code?
轉(zhuǎn)載于:https://www.cnblogs.com/lujiaju6555/p/6795935.html
總結(jié)
以上是生活随笔為你收集整理的[BZOJ4403]序列统计的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 移动相关HTML设置
- 下一篇: 移动端H5页面高清多屏适配方案