题意:给定三个正整数N、L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量。输出答案对10^6+3取模的结果。
我的数学好差啊。。。
推式子见:http://www.cnblogs.com/Var123/p/5546290.html
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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 ",(ans-1+p)%p); } return 0; }