题目大意:

给定n m

在n个数中最多选择m个的所有方案

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
const int mod=1e9+;
const int N=1e5+; /********组合数模板*********/
LL pow_mod(LL a, LL b) {
LL res = 1LL; a %= mod;
while(b){
if(b & ) res = res * a % mod;
a = a * a % mod;
b >>= ;
} return res;
}
LL inv(LL a) { return pow_mod(a, mod-); }
LL F[N], Finv[N];//F是阶乘,Finv是逆元的阶乘
void init() {
F[] = Finv[] = 1LL;
for(int i = ; i < N; i ++){
F[i] = F[i-] * 1LL * (LL)i % mod;
Finv[i] = Finv[i-] * 1LL * inv(i) % mod;
}
} // O(n)预处理
LL C(LL n, LL m) {
if(m < || m > n) return ;
return F[n] * 1LL * Finv[n - m] % mod * Finv[m] % mod;
} // O(1)获得组合数C(n,m)
/**************************/ LL res[N]; /********莫队*********/
int len;
struct Q {
LL n,m;
int block, id;
bool operator <(const Q& q)const {
if(block==q.block) return n<q.n;
return block<q.block;
}
}q[N];
void Mo(int t) {
LL L=, R=, ans=1LL;
for(int i=;i<t;i++) {
LL l=q[i].n, r=q[i].m;
while(L>l) ans=((ans+C(L-1LL,R))%mod*Finv[])%mod, L--;
while(L<l) ans=(*ans%mod-C(L,R)+mod)%mod, L++;
while(R<r) ans=(ans+C(L,R+))%mod, R++;
while(R>r) ans=(ans-C(L,R)+mod)%mod, R--;
res[q[i].id]=ans;
}
}
/**************************/ int main()
{
init(); len=sqrt(N);
int t; scanf("%d",&t);
for(int i=;i<t;i++) {
scanf("%lld%lld",&q[i].n,&q[i].m);
q[i].block=q[i].m/len; q[i].id=i;
}
sort(q,q+t);
Mo( t);
for(int i=;i<t;i++)
printf("%lld\n",res[i]); return ;
}

HDU6333 莫队+组合数的更多相关文章

  1. HDU 6333 莫队+组合数

    Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  2. Harvest of Apples (HDU多校第四场 B) (HDU 6333 ) 莫队 + 组合数 + 逆元

    题意大致是有n个苹果,问你最多拿走m个苹果有多少种拿法.题目非常简单,就是求C(n,0)+...+C(n,m)的组合数的和,但是询问足足有1e5个,然后n,m都是1e5的范围,直接暴力的话肯定时间炸到 ...

  3. HDU6333 莫队+组合数学

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题意: T次询问,每次询问n个苹果中最多拿m个苹果的方法数 题解: 因为T为1e5,所以直接做时间 ...

  4. 联赛模拟测试12 C. sum 莫队+组合数

    题目描述 分析 \(80\) 分的暴力都打出来了还是没有想到莫队 首先对于 \(s[n][m]\) 我们可以很快地由它推到 \(s[n][m+1]\) 和 \(s[n][m-1]\) 即 \(s[n] ...

  5. hdu6333 Problem B. Harvest of Apples(组合数+莫队)

    hdu6333 Problem B. Harvest of Apples 题目传送门 题意: 求(0,n)~(m,n)组合数之和 题解: C(n,m)=C(n-1,m-1)+C(n-1,m)    设 ...

  6. HDU-6333 Problem B. Harvest of Apples 莫队

    HDU-6333 题意: 有n个不同的苹果,你最多可以拿m个,问有多少种取法,多组数据,组数和n,m都是1e5,所以打表也打不了. 思路: 这道题要用到组合数的性质,记S(n,m)为从n中最多取m个的 ...

  7. Problem B. Harvest of Apples(杭电2018年多校+组合数+逆元+莫队)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题目: 题意:求C(n,0)+C(n,1)+……+C(n,m)的值. 思路:由于t和n数值范围太 ...

  8. 【魔改】莫队算法+组合数公式 杭电多校赛4 Problem B. Harvest of Apples

    http://acm.hdu.edu.cn/showproblem.php?pid=6333 莫队算法是一个离线区间分块瞎搞算法,只要满足:1.离线  2.可以O(1)从区间(L,R)更新到(L±1, ...

  9. 2018.10.23 NOIP训练 Leo的组合数问题(组合数学+莫队)

    传送门 好题. 考察了莫队和组合数学两个知识板块. 首先需要推出单次已知n,mn,mn,m的答案的式子. 我们令f[i]f[i]f[i]表示当前最大值为第iii个数的方案数. 显然iii之后的数都是单 ...

随机推荐

  1. 使用clr 调用C#编写的dll中的方法的全解释

    使用clr 调用C#编写的dll中的方法的全解释1.数据库初始化:将下面这段代码直接在运行就可以初始化数据库了exec sp_configure 'show advanced options', '1 ...

  2. 19-字符串匹配(kmp || substr,find)

    链接:https://www.nowcoder.com/acm/contest/77/C来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  3. Django框架 之 form组件的钩子

    Django框架 之 form组件的钩子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3 ...

  4. Spring.Web.Mvc 注入(控制器属性注入)

    1.web.config配置 <?xml version="1.0" encoding="utf-8"?><!-- 有关如何配置 ASP.NE ...

  5. hdu 4740 The Donkey of Gui Zhou

    1.扯犊子超多if else 判断的代码,华丽丽的TLE. #include<stdio.h> #include<string.h> #define N 1010 int ma ...

  6. 8.python 系统批量运维管理器之pexpect模块

    小插曲 前几节讲了paramiko模块,但是pexpect模块的功能几乎跟paramiko一样,先来分析一下: 1.各自介绍 pexpect是一个通过启动子程序,使用正则表达式对程序输出做出特定响应, ...

  7. C# 将一个DataTable的结构直接复制到另一个DataTable

    DataTable.Clone();//仅复制表结构DataTable.Copy();//复制表结构及数据 DataTable.ImportRow(DataRow);//复制行数据到新表 DataRo ...

  8. UML类之间的关系

    原文:http://www.cnblogs.com/me115/p/4092632.html 下面详细介绍这六种关系: 类之间的关系 泛化关系(generalization) 类的继承结构表现在UML ...

  9. jQuery之方法绑定(事件注册)代码小结

    1.最直接的模式,直接将一个function对象传入方法函数,如下面的click(),好处坏处一看便知 $("#btnComfirmChooseCompany").click(fu ...

  10. 以太坊系列之五: p2p的nat模块--以太坊源码学习

    p2p的nat模块 该模块相对比较简单,因为nat的真正实现并不在此模块,主要是使用了第三方的nat-upnp和nat-pmp来实现真正的穿透(端口映射). 对外公布的接口 ```go // An i ...