博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
杭电多校 Harvest of Apples 莫队
阅读量:4639 次
发布时间:2019-06-09

本文共 1681 字,大约阅读时间需要 5 分钟。

问题 B: Harvest of Apples

时间限制: 1 Sec  内存限制: 128 MB

提交: 78  解决: 35
[] [] [] [命题人:]

题目描述

There are n apples on a tree, numbered from 1 to n.

Count the number of ways to pick at most m apples.

 

输入

The first line of the input contains an integer T (1≤T≤105) denoting the number of test cases.

Each test case consists of one line with two integers n,m (1≤m≤n≤105).

 

输出

For each test case, print an integer representing the number of ways modulo 109+7.

 

样例输入

25 21000 500

 

样例输出

16924129523

 

[][]

官方题解

重点就是划出来的公式,然后套莫队即可

代码:

#include 
using namespace std;const int maxn=1e5+100;#define INF 0x3f3f3f;const int mod=1e9+7;typedef long long ll;struct node{ ll n,m; int p;}s[maxn];ll block;ll fac[maxn],inv[maxn];ll ans[maxn];ll noww;ll qpow(ll x,ll y){ ll ret = 1; while(y){ if(y&1) ret = ret * x % mod; x = x * x % mod; y >>= 1; } return ret;}void init(){ fac[0] = 1; for(int i=1; i
=0; i--) inv[i] = inv[i+1] * (i+1) % mod;}ll C(ll x,ll y){ return fac[x] * inv[y] %mod * inv[x-y] % mod;}bool cmp(node x,node y){ if(x.n / block == y.n / block) return x.m < y.m; return x.n / block < y.n / block;}int main(){ int t; scanf("%d",&t); block = sqrt(maxn); init(); for(int i=0; i
s[i].n){ noww = (noww + C(l-1,r)) % mod * inv[2] % mod; l--; } while(r < s[i].m){ r++; noww = (noww + C(l,r)) % mod; } while(r > s[i].m){ noww = (noww + mod - C(l,r)) % mod; r--; } ans[s[i].p] = noww; } for(int i=0; i

刚刚学了莫队,赶紧把原来两个莫队给补了

转载于:https://www.cnblogs.com/renxiaomiao/p/9642664.html

你可能感兴趣的文章
视频教程--ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库
查看>>
第五次作业
查看>>
织梦教程
查看>>
杭电多校 Harvest of Apples 莫队
查看>>
java 第11次作业:你能看懂就说明你理解了——this关键字
查看>>
C/C++心得-结构体
查看>>
函数名作为参数传递
查看>>
apt-get for ubuntu 工具简介
查看>>
数值计算算法-多项式插值算法的实现与分析
查看>>
day8-异常处理与网络编程
查看>>
Python基础-time and datetime
查看>>
Linux epoll 笔记(高并发事件处理机制)
查看>>
shell脚本练习01
查看>>
WPF图标拾取器
查看>>
通过取父级for循环的i来理解闭包,iife,匿名函数
查看>>
HDU 3374 String Problem
查看>>
数据集
查看>>
打印python包含汉字报SyntaxError: Non-ASCII character '\xe4' in file
查看>>
[Leetcode] unique paths ii 独特路径
查看>>
HDU 1217 Arbitrage (Floyd + SPFA判环)
查看>>