HDU6333 莫队+组合数
题目大意:
给定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 莫队+组合数的更多相关文章
- HDU 6333 莫队+组合数
Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K ...
- Harvest of Apples (HDU多校第四场 B) (HDU 6333 ) 莫队 + 组合数 + 逆元
题意大致是有n个苹果,问你最多拿走m个苹果有多少种拿法.题目非常简单,就是求C(n,0)+...+C(n,m)的组合数的和,但是询问足足有1e5个,然后n,m都是1e5的范围,直接暴力的话肯定时间炸到 ...
- HDU6333 莫队+组合数学
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6333 题意: T次询问,每次询问n个苹果中最多拿m个苹果的方法数 题解: 因为T为1e5,所以直接做时间 ...
- 联赛模拟测试12 C. sum 莫队+组合数
题目描述 分析 \(80\) 分的暴力都打出来了还是没有想到莫队 首先对于 \(s[n][m]\) 我们可以很快地由它推到 \(s[n][m+1]\) 和 \(s[n][m-1]\) 即 \(s[n] ...
- 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) 设 ...
- HDU-6333 Problem B. Harvest of Apples 莫队
HDU-6333 题意: 有n个不同的苹果,你最多可以拿m个,问有多少种取法,多组数据,组数和n,m都是1e5,所以打表也打不了. 思路: 这道题要用到组合数的性质,记S(n,m)为从n中最多取m个的 ...
- 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数值范围太 ...
- 【魔改】莫队算法+组合数公式 杭电多校赛4 Problem B. Harvest of Apples
http://acm.hdu.edu.cn/showproblem.php?pid=6333 莫队算法是一个离线区间分块瞎搞算法,只要满足:1.离线 2.可以O(1)从区间(L,R)更新到(L±1, ...
- 2018.10.23 NOIP训练 Leo的组合数问题(组合数学+莫队)
传送门 好题. 考察了莫队和组合数学两个知识板块. 首先需要推出单次已知n,mn,mn,m的答案的式子. 我们令f[i]f[i]f[i]表示当前最大值为第iii个数的方案数. 显然iii之后的数都是单 ...
随机推荐
- 一个小仓鼠的js动画
直接在网页打开就可以玩了: http://cdn.abowman.com/widgets/hamster/hamster.swf?up_bodyColor=f0e9cc&up_feetColo ...
- 690. Employee Importance员工权限重要性
[抄题]: You are given a data structure of employee information, which includes the employee's unique i ...
- 616. Add Bold Tag in String加粗字符串
[抄题]: Given a string s and a list of strings dict, you need to add a closed pair of bold tag <b&g ...
- c语言实践 用1角 2角 5角 凑成10元钱的方法
/* 用1角,2角,5角凑出10元钱,有几种办法. 也就是0.1a+0.2b+0.3c=10,化简一下就是 a=100-2b-3c 因为a的范围是0到100,所以弄一个循环 把a的值从0尝试到100, ...
- oracle使用PLSQL免安装客户端
2. 下载Oracle Instant Client (32-bit) 只需要下载instantclient-basic-nt-11.2.0.3.0.zip就可以了,其它的都是一些根据不同需要扩展的包 ...
- PHP中 null ,false , 区别
先来测试一下吧: if(0 ==''){ echo '<br/>在PHP中0 ==\'\'' ; } if(0 !==''){ echo '<br/>在PHP中0 !==\'\ ...
- 自定义JTabbedPane 标签风格
自定义JTabbedPane 标签风格 2012年03月09日 20:33:12 阅读数:2435 demo 下载地址:http://download.csdn.net/detail/jinannan ...
- HTTP Modules versus ASP.NET MVC Action Filters
from:http://odetocode.com/blogs/scott/archive/2011/01/17/http-modules-versus-asp-net-mvc-action-filt ...
- 【JAVA】虚拟机指令集
[JAVA]虚拟机指令集 – – – 0x00 nop 什么都不做 0x01 aconst_null 将null推送至栈顶 0x02 iconst_m1 将int型-1推送至栈顶 0x03 icons ...
- Python Lambda 的简单用法
下面代码简单举例介绍以下 lambda的用法. from functools import reduce #1 python lambda会创建一个函数对象,但不会把这个函数对象赋给一个标识符,而de ...