[bzoj4403]序列统计 Lucas定理
来源:互联网 发布:美工穿什么衣服 编辑:程序博客网 时间:2024/05/19 11:18
4403: 序列统计
Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 759 Solved: 363
[Submit][Status][Discuss]
Description
给定三个正整数N、L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量。输出答案对10^6+3取模的结果。
Input
输入第一行包含一个整数T,表示数据组数。
第2到第T+1行每行包含三个整数N、L和R,N、L和R的意义如题所述。
1≤N,L,R≤10^9,1≤T≤100,输入数据保证L≤R。
Output
输出包含T行,每行有一个数字,表示你所求出的答案对10^6+3取模的结果。
Sample Input
2
1 4 5
2 4 5
1 4 5
2 4 5
Sample Output
2
5
//【样例说明】满足条件的2个序列为[4]和[5]。
5
//【样例说明】满足条件的2个序列为[4]和[5]。
HINT
Source
求sigmaC(m+i-1,m-1) 1<=i<=N
即C(m+n,m-1)-1
#include<iostream>#include<cstdio>#define mod 1000003using namespace std;typedef long long ll;int n,m,l,r,T;ll fac[mod+5],infa[mod+5];void init(){int i; fac[0] = infa[1] = infa[0] = 1;for( i = 1; i < mod; i++ ) fac[i] = fac[i-1]*i%mod;for( i = 2; i < mod; i++ ) infa[i] = (mod-mod/i)*infa[mod%i]%mod;for( i = 1; i < mod; i++ ) infa[i] = (infa[i]*infa[i-1])%mod;}ll C( int n, int m ){if( n < m ) return 0;if( n < mod && m < mod ) return fac[n] * infa[m] % mod * infa[n-m] % mod;else return C(n%mod,m%mod)*C(n/mod,m/mod)%mod;}int main(){init();scanf("%d", &T);while(T--){scanf("%d%d%d", &n, &l, &r);m = r - l + 1;printf("%lld\n",(C(m+n,n)+mod-1)%mod);}return 0;}
阅读全文
0 0
- 【BZOJ4403】序列统计【Lucas定理】
- [BZOJ4403][Lucas定理]序列统计
- [bzoj4403]序列统计 Lucas定理
- 【lucas定理】BZOJ4403 序列统计
- 【Lucas定理】BZOJ4403[序列统计]题解
- BZOJ4403 序列统计 [Lucas]
- Bzoj4403序列统计:Lucas初探,组合数学
- 【BZOJ4403】【lucas】【组合数】序列统计 题解
- bzoj4403 序列统计 ( 组合数学 + lucas )
- bzoj4403 lucas定理模板
- bzoj4403 序列统计 组合
- 【BZOJ4403】序列统计
- BZOJ4403: 序列统计
- BZOJ4403 序列统计
- bzoj4403: 序列统计
- bzoj4403 序列统计
- BZOJ4403: 序列统计
- bzoj4403 序列统计
- ubuntu安装vue
- Linux修改文件夹及文件权限
- 数据结构(图遍历--广度优先遍历)
- unity网络连接的学习
- leetcode 582. Kill Process
- [bzoj4403]序列统计 Lucas定理
- 使用firewall-cmd命令配置防火墙
- Divide_Two_Integers
- 网易春招面试题--搬砖
- Activity之间跳转和参数传递
- Linux shell实现MySQL数据库简单查询&&MySQL多表联合查询
- 安卓SharedPreferences存储与读取
- 如何通俗地理解 Gradle?
- leetcode_162. Find Peak Element