Count Sequences
\(考虑问题的转换,即把用n个球,分为r-l+2个部分,其中第1部分表示该区域的球值为l,第二部分表示该区域的球值为l+1\)
\(......第r-l+2部分为不选该区域的球\)
\(该问题等价于在n+1个空中插r-l+1块板,其中一个空可以插多个也可以不插\)
\(方案数即为\binom{r-l+n+1}{n}\)
\(但长度为1-n,因此要减去所有板都在1的情况,即为\binom{r-l+n+1}{n}-1\)
\(当然,n,r,l很大,因此要用Lucas定理\)
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 1100050;
const int MOD=1e6+3;
int cnt;
long long Pow(int a, int b, int p) {
long long ans = 1;
long long base = a;
base %= p;
while (b) {
if (b & 1) {
ans *= base;
ans %= p;
}
base *= base;
base %= p;
b >>= 1;
}
return ans;
}
long long inv(int a, int p) {
return Pow(a, p - 2, p);
}
long long fac[MAXN], inv_fac[MAXN];
long long C(long long n, long long m) {
if (m < 0) {
return 0;
}
if (n < m) {
return 0;
}
if (m == 0||n==m)
return 1;
long long k = fac[n];
long long ans = k * inv(fac[n - m],MOD);
ans %= MOD;
ans = ans * inv(fac[m],MOD);
ans %= MOD;
return ans;
}
long long Lucas(int n,int m)
{
if(!m)
{
return 1;
}
return C(n%MOD,m%MOD)*Lucas(n/MOD,m/MOD)%MOD;
}
int t;
long long n,l,r;
signed main() {
fac[0] = 1;
for (int i = 1; i <= MOD-1; i++) {
fac[i] = fac[i - 1] * i;
fac[i] %= MOD;
}
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld %lld",&n,&l,&r);
printf("%lld\n",(Lucas(r-l+n+1,n)-1+MOD)%MOD);
}
}
Count Sequences的更多相关文章
- 算法 - 求和为n的连续正整数序列(C++)
//************************************************************************************************** ...
- CRT/LCD/VGA Information and Timing
彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for red, green, and blue phosphor dots)2. 电子束 Electron ...
- CRT/LCD/VGA Information and Timing【转】
转自:http://www.cnblogs.com/shangdawei/p/4760933.html 彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for ...
- Linux command line exercises for NGS data processing
by Umer Zeeshan Ijaz The purpose of this tutorial is to introduce students to the frequently used to ...
- nodejs api 中文文档
文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格 ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- Python数据类型之“序列概述与基本序列类型(Basic Sequences)”
序列是指有序的队列,重点在"有序". 一.Python中序列的分类 Python中的序列主要以下几种类型: 3种基本序列类型(Basic Sequence Types):list. ...
- 【leetcode】Repeated DNA Sequences(middle)★
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合
题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...
随机推荐
- 【JAVA】【Basic】概念
1. 历史 1.1. Sun, Green Project, 90年代初,为机顶盒提供一个统一的语言层,oak-->Java, James Gosling, Sun World 1995:JAV ...
- springmvc资源文件访问不到,undefined,jsp引用js文件目录
资源访问失败: 该模块下springmvc.xml文件中添加配置: <mvc:resources mapping="/js/**" location="/js/&q ...
- 使用jquery完成抽奖图片滚动的效果
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>jq ...
- list.jsp页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@tag ...
- ICCV2021 | 用于视觉跟踪的学习时空型transformer
前言 本文介绍了一个端到端的用于视觉跟踪的transformer模型,它能够捕获视频序列中空间和时间信息的全局特征依赖关系.在五个具有挑战性的短期和长期基准上实现了SOTA性能,具有实时性,比 ...
- 测试开发实战[提测平台]17-Flask&Vue文件上传实现
微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. 先回顾下在此系列第8次分享给出的预期实现的产品原型和需求说明,如下图整体上和前两节实现很相似,只不过一般测试报告要写的内容可能比较多,就多 ...
- CF41C Email address 题解
Content 有一个字符串 \(s\),它满足以下要求: 只包含 ..@ 和小写字母. 不以 . 为开头或者结尾. 不以 @ 为开头或者结尾,并只能包含一个 @. 请将其进行如下操作,使得这个字符串 ...
- AOP——面向切面编程
目录 什么是AOP AOP的作用和优势 作用: 优势: AOP相关术语 AOP的实现方式 使用动态代理的方式 使用XML的方式 使用注解的方式 什么是AOP AOP:全称是Aspect Oriente ...
- 使用react搭建组件库:react+typescript+storybook
前期准备 1. 初始化项目 npx create-react-app react-components --template typescript 2. 安装依赖 使用哪种打包方案:webpack/r ...
- 输入npm install 报错npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.13.1 postinstall: `node scripts/build.js`
输入npm install 报以下错误 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-sass@4.13.1 postinstall: ...