bzoj 4403 序列统计 卢卡斯定理
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
Sample Output
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 序列统计 卢卡斯定理的更多相关文章
- 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 序列统计(Lucas)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4403 [题目大意] 给定三个正整数N.L和R,统计长度在1到N之间, 元素大小都在L到 ...
- [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: 序列统计【lucas+组合数学】
首先,给一个单调不降序列的第i位+i,这样就变成了单调上升序列,设原来数据范围是(l,r),改过之后变成了(l+1,r+n) 在m个数里选长为n的一个单调上升序列的方案数为\( C_m^n \),也就 ...
- 【BZOJ 4403】 4403: 序列统计 (卢卡斯定理)
4403: 序列统计 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 653 Solved: 320 Description 给定三个正整数N.L和R, ...
- 【BZOJ4403】序列统计 Lucas定理
[BZOJ4403]序列统计 Description 给定三个正整数N.L和R,统计长度在1到N之间,元素大小都在L到R之间的单调不降序列的数量.输出答案对10^6+3取模的结果. Input 输入第 ...
- bzoj 3782 上学路线 卢卡斯定理 容斥 中国剩余定理 dp
LINK:上学路线 从(0,0)走到(n,m)每次只能向上或者向右走 有K个点不能走求方案数,对P取模. \(1\leq N,M\leq 10^10 0\leq T\leq 200\) p=10000 ...
随机推荐
- uboot中fdt命令的使用
转载:https://blog.csdn.net/voice_shen/article/details/7441894 依linux community的要求,从linux-3.5后,新提交的code ...
- df值自由度学习[转载]
转自:https://www.applysquare.com/topic-cn/78TAnIzZ6/ https://zhidao.baidu.com/question/175605082855699 ...
- PAT 1003 Emergency[图论]
1003 Emergency (25)(25 分) As an emergency rescue team leader of a city, you are given a special map ...
- [LeetCode] 221. Maximal Square _ Medium Tag: Dynamic Programming
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and re ...
- Python Pandas找到缺失值的位置
python pandas判断缺失值一般采用 isnull(),然而生成的却是所有数据的true/false矩阵,对于庞大的数据dataframe,很难一眼看出来哪个数据缺失,一共有多少个缺失数据,缺 ...
- jmeter 测试websocket接口(二)
1.到https://github.com/maciejzaleski/JMeter-WebSocketSampler下载Jmeter的WebSocket协议的支持插件:JMeterWebSocket ...
- DW课堂练习 用所学的知识去制作一个 (邮箱的注册页面)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- thinkphp 隐藏表单验证原理
function savetoken() //创建session('hash') ,然后在魔板中表单中加入隐藏域 getsession('hash'),提交表单验证值是否一样,如果一样验证通过,同时重 ...
- python start
由于工作关系,新学习使用了python,感觉能非常快速和方便的开发,看完<简明 Python 教程>就跃跃欲试,实际用的是发现有些和C#的理解不一样 (1)如何筛选元组 例如 recor ...
- MySQL从删库到跑路_高级(七)——事务和锁
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.事务简介 1.事务简介 事务(Transaction)是指作为单个逻辑工作单元执行的一系列操作. 2.事物的特效 ...