4403:序列统计

Time Limit: 3 Sec  Memory Limit: 128 MB

Description

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

Input

输入第一行包含一个整数T,表示数据组数。第2到第T+1行每行包含三个整数N、L和R,N、L和R的意义如题所述。

Output

输出包含T行,每行有一个数字,表示你所求出的答案对106+3取模的结果。

Sample Input

2
1 4 5
2 4 5

Sample Output

2
5

HINT

提示

【样例说明】满足条件的2个序列为[4]和[5]。

【数据规模和约定】对于100%的数据,1≤N,L,R≤10^9,1≤T≤100,输入数据保证L≤R。

思路:得到一个这样的二维数组:表示第i的长度结尾为L的个数

   L     L+1      L+2    L+3    .......    R

1      1     1          1        1        ......     1

2      1     2          3        4        ......     R

.....

N     1     C(N,1)                       ......    C((R-L+1+N),N)

答案为取一个矩阵的和,sigma;

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 999999999
#define pi 4*atan(1)
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
ll f[];
void init(int p) { //f[n] = n!
f[] = ;
for (int i=; i<=p; ++i) f[i] = f[i-] * i % p;
}
ll pow_mod(ll a, ll x, int p) {
ll ret = ;
while (x) {
if (x & ) ret = ret * a % p;
a = a * a % p;
x >>= ;
}
return ret;
} ll Lucas(ll n, ll k, ll p) { //C (n, k) % p
ll ret = ;
while (n && k) {
ll nn = n % p, kk = k % p;
if (nn < kk) return ; //inv (f[kk]) = f[kk] ^ (p - 2) % p
ret = ret * f[nn] * pow_mod (f[kk] * f[nn-kk] % p, p - , p) % p;
n /= p, k /= p;
}
return ret;
}
int main()
{
ll x,y,z,i,t;
init();
int T;
ll N,L,R;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld%lld",&N,&L,&R);
ll n,k;
ll ans=;
k=N;
n=(R-L++N);
ans+=Lucas(n,k,);
printf("%lld\n",(ans+)%);
}
return ;
}

bzoj 4403 序列统计 卢卡斯定理的更多相关文章

  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 序列统计(Lucas)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4403 [题目大意] 给定三个正整数N.L和R,统计长度在1到N之间, 元素大小都在L到 ...

  4. [BZOJ 4403]序列统计

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

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

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

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

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

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

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

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

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

  9. bzoj 3782 上学路线 卢卡斯定理 容斥 中国剩余定理 dp

    LINK:上学路线 从(0,0)走到(n,m)每次只能向上或者向右走 有K个点不能走求方案数,对P取模. \(1\leq N,M\leq 10^10 0\leq T\leq 200\) p=10000 ...

随机推荐

  1. rsync+inotify安装配置 实时同步文件

    安装 #安装inotify 工具 [root@localhost ~]# yum install inotify-tools -y 常用命令 [root@localhost ~]# inotifywa ...

  2. 浅谈Java中的==和equals

    引言 最近在看TIJ,看到==和equals相关内容,今天就来简单的总结下. 关系操作符== 书中对关系操作符的描述是这样的:"关系操作符生成的是一个boolean结果,它们计算的是操作数的 ...

  3. Summary: Difference between null and empty String

    String s1 = ""; means that the empty String is assigned to s1. In this case, s1.length() i ...

  4. Rpgmakermv(4 )doc of TerraxLights

    我只做简要翻译. To activate the script in an area, do the following: 1. Put an event switch into the map. 2 ...

  5. CAMediaTiming`协议(9.1 图层时间)

    #CAMediaTiming`协议 CAMediaTiming协议定义了在一段动画内用来控制逝去时间的属性的集合,CALayer和CAAnimation都实现了这个协议,所以时间可以被任意基于一个图层 ...

  6. python isinstance()与type()的区别

    例如在继承上的区别: isinstance() 会认为子类是一种父类类型,考虑继承关系. type() 不会认为子类是一种父类类型,不考虑继承关系. class A: pass class B(A): ...

  7. 通过canal实现把MySQL数据实时增量到kafka

    说明:我们有一个业务需要把mysql中一些表实时同步到大数据集群hbase上面,我们先通过sqoop把表中数据全量导入到hbase中,然后再通过canal定位的某个binlog的position,来实 ...

  8. linux常用命令:top 命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是 一个动态显示过程,即可以通过用户按键来不断刷 ...

  9. Linux服务器---apache支持cgi

    Apache支持cgi  1.打开Apache配置文件httpd.conf,搜索“cgi”,找到下面的一段,去掉“addhandler”前面的“#“,这样就开启了Apache的cgi功能 [root@ ...

  10. Bootstrap+AngularJS对话框实例

    <script type="text/javascript" src="/assets/JS/plugins/jquery.min.js">< ...