BZOJ 4403 序列统计(Lucas)
【题目链接】 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)的更多相关文章
- Bzoj 4403: 序列统计 Lucas定理,组合数学,数论
4403: 序列统计 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 328 Solved: 162[Submit][Status][Discuss] ...
- BZOJ 4403: 序列统计 数学 lucas
4403: 序列统计 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4403 Description 给定三个正整数N.L和R,统计长度在 ...
- bzoj 4403 序列统计 卢卡斯定理
4403:序列统计 Time Limit: 3 Sec Memory Limit: 128 MB Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调 ...
- bzoj 4403: 序列统计【lucas+组合数学】
首先,给一个单调不降序列的第i位+i,这样就变成了单调上升序列,设原来数据范围是(l,r),改过之后变成了(l+1,r+n) 在m个数里选长为n的一个单调上升序列的方案数为\( C_m^n \),也就 ...
- [BZOJ 4403]序列统计
Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第一行包含一个整数T,表示数据组 ...
- bzoj 4403 序列统计——转化成组合数的思路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4403 先说说自己的想法吧. 设f[ i ][ j ]表示当前在倒数第 i 个位置,当前和后面 ...
- 【BZOJ 4403】 4403: 序列统计 (卢卡斯定理)
4403: 序列统计 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 653 Solved: 320 Description 给定三个正整数N.L和R, ...
- BZOJ4403 序列统计—Lucas你好
绝对是全网写的最详细的一篇题解 题目:序列统计 代码难度:简单 思维难度:提高+-省选 讲下题面:给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案 ...
- 【BZOJ4403】序列统计 Lucas定理
[BZOJ4403]序列统计 Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第 ...
随机推荐
- 极致的 Hybrid:航旅离线包再加速!(转)
资源离线的思路简单.场景复杂,最复杂的就是 H5 活动页面的离线化.Mobile Web 在弱网提速的唯一的办法就是坚决杜绝不必要的(运行时)网络请求,即除了 Json 格式的动态数据和其携带的商品配 ...
- Tornado 安装及简单程序示例
1.安装步骤:tar xvzf tornado-3.2.tar.gz cd tornado-3.2 python setup.py build sudo python setup.py install ...
- mysql in/no in/like
% 任意字符 _ 任意一个字符 in (value,......) 在这里 not in (value,......) 不在这里 mysql> select 'a' not in (1,2,3, ...
- bind类成员函数
首先描述一个情景: 先贴出代码: class Solution { public: bool compare(int a, int b) { return a > b; } int functi ...
- python基础===python os.path模块
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- gnu app url[web][5星]
http://www.gnu.org/software/software.zh-cn.html http://linux.chinaunix.net/news/2010/12/07/1175310.s ...
- sleep() 函数
函数名: sleep 功 能: 执行挂起一段时间 用 法: unsigned sleep(unsigned seconds); 头文件 #include <windows.h> # wi ...
- wifi驱动移植
目标板:Hi3518 内核版本:linux3.0.8 1.修改makefile #PLATFORM = PC //注释掉 PLATFORM = HI3518 //支持平台 ifeq ($(PLAT ...
- html5重力感应事件之DeviceMotionEvent
前言 今天主要介绍一下html5重力感应事件之DeviceMotionEvent,之前我的一篇文章http://www.haorooms.com/post/jquery_jGestures, 介绍了第 ...
- node起server--axios做前端请求----进行CORS--跨域请求
CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing). 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从 ...