【题目链接】 http://www.lydsy.com/JudgeOnline/problem.php?id=4403

【题目大意】

  给定三个正整数N、L和R,统计长度在1到N之间,
  元素大小都在L到R之间的单调不降序列的数量。输出答案对10^6+3取模的结果。

【题解】

  我们用插板法,在设m=R-L+1,答案等价于在n+m个球里面拿出m个球变成插板,
  那么答案就是拿掉这些插板之后的分堆。

【代码】

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1000010;
const LL mod=1000003;
namespace Lucas{
LL f[N],rf[N];
LL mul(LL x,LL y,LL P){return (x*y-(LL)(x/(long double)P*y+1e-3)*P+P)%P;}
LL pow(LL a,LL b,LL P){LL t=1;for(;b;b>>=1,a=mul(a,a,P))if(b&1)t=mul(t,a,P);return t;}
void Initialize(int n){
f[0]=1;for(int i=1;i<n;i++)f[i]=f[i-1]*i%n;
rf[n-1]=pow(f[n-1],n-2,n);
for(int i=n-1;i;i--)rf[i-1]=rf[i]*i%n;
}
LL C(int n,int m,int mod){
if(m>n||m<0||n<0)return 0;
return f[n]*rf[m]%mod*rf[n-m]%mod;
}
LL lucas(LL n,LL m,LL P){
if(n<m)return 0;
if(!m||n==m)return 1;
return C(n%P,m%P,P)*lucas(n/P,m/P,P)%P;
}
}
int T;
LL n,l,r;
int main(){
scanf("%d",&T);
using namespace Lucas;
Initialize(mod);
while(T--){
scanf("%lld%lld%lld",&n,&l,&r);
printf("%lld\n",(lucas(n+r-l+1,r-l+1,mod)+mod-1)%mod);
}return 0;
}

BZOJ 4403 序列统计(Lucas)的更多相关文章

  1. Bzoj 4403: 序列统计 Lucas定理,组合数学,数论

    4403: 序列统计 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 328  Solved: 162[Submit][Status][Discuss] ...

  2. BZOJ 4403: 序列统计 数学 lucas

    4403: 序列统计 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4403 Description 给定三个正整数N.L和R,统计长度在 ...

  3. bzoj 4403 序列统计 卢卡斯定理

    4403:序列统计 Time Limit: 3 Sec  Memory Limit: 128 MB Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调 ...

  4. bzoj 4403: 序列统计【lucas+组合数学】

    首先,给一个单调不降序列的第i位+i,这样就变成了单调上升序列,设原来数据范围是(l,r),改过之后变成了(l+1,r+n) 在m个数里选长为n的一个单调上升序列的方案数为\( C_m^n \),也就 ...

  5. [BZOJ 4403]序列统计

    Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第一行包含一个整数T,表示数据组 ...

  6. bzoj 4403 序列统计——转化成组合数的思路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4403 先说说自己的想法吧. 设f[ i ][ j ]表示当前在倒数第 i 个位置,当前和后面 ...

  7. 【BZOJ 4403】 4403: 序列统计 (卢卡斯定理)

    4403: 序列统计 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 653  Solved: 320 Description 给定三个正整数N.L和R, ...

  8. BZOJ4403 序列统计—Lucas你好

    绝对是全网写的最详细的一篇题解  题目:序列统计 代码难度:简单 思维难度:提高+-省选 讲下题面:给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案 ...

  9. 【BZOJ4403】序列统计 Lucas定理

    [BZOJ4403]序列统计 Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第 ...

随机推荐

  1. Java 将html导出word格式

    @RequestMapping("download") public void exportWord( HttpServletRequest request, HttpServle ...

  2. 【转】jpg文件格式详解

    JPEG(Joint Photographic Experts Group)是联合图像专家小组的英文缩写.它由国际电话与电报咨询委员会CCITT(The International Telegraph ...

  3. Python模块学习 - ConfigParser

    配置文件 很多软件都用到了配置文件,像git运行的时候会读取~/gitconfig,MySQL运行的时候会读取/etc/my.cnf,Python 提供的包管理工具pip命令,也会去读取~/.pip/ ...

  4. ADC 計算時,階數的選擇

    reference : ADC 階數的計算

  5. FC4-i386-SRPMS

    [重点] http://archives.fedoraproject.org/pub/archive/fedora/linux/core/6/ http://archives.fedoraprojec ...

  6. C# 读写XML文件示例

    using System; using System.Collections.Generic; using System.Text; using System.Configuration; using ...

  7. CNN中已知input_size、kernel_size、padding、stide计算output公式的理解

    在进行卷积运算和池化的时候,对于输入图像大小为input_size,给定kernel_size.padding.stride,计算得出output_size为: output_size =1+ (in ...

  8. ado中dispose和close的区别,摘自网络

    Close() and Dispose() are basically the same thing on an ADO.NET connection object for providers shi ...

  9. linux命令(37):locate命令

    1.命令格式: Locate [选择参数] [样式] 2.命令功能: locate命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更新,updatedb是由cron daemon周期 ...

  10. 在写一次epoll

    epoll & select & poll只能处理IO相关的操作,epoll每一个操作必须注册到时间监控机制中,并且还需要进程或者线程进行管理. 多进程/多线程 和epoll相比较 e ...