Problem Description
There are n apples on a tree, numbered from 1 to n.Count the number of ways to pick at most m apples.
Input
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).
Output
For each test case, print an integer representing the number of ways modulo 109+7.
Sample Input
2 5 2 1000 500
Sample Output
16 924129523
Source
Recommend
这题刚写的时候 公式及其的容易推 C(n,0)+C(n,1)+C(n,2)+。。。+C(n,m)
然后一直在想能不能化简这一项一项的求 复杂度会爆炸的
最后的题解是莫队
C(n,m)=C(n-1,m-1)+C(n-1,m)
设 S(n,m)=C(n,0)+C(n,1)+C(n,2)+。。。+C(n,m)
然后将S(n,m) 通过 第一个公式 拆项
最后化简 变为 S(n,m)=2*S(n-1,m)-C(n-1,m);
预处理阶乘逆元 然后就 OK了
莫队大法好
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include