You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 2010;
|
|
|
|
|
const int p = 1e9 + 7;
|
|
|
|
|
int c[N][N];
|
|
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
|
/*
|
|
|
|
|
功能:第0列初始化为1,现实意义:C(n,0)=1
|
|
|
|
|
理解:从n个元素中,每次取出0个元素,也就是每次都不取出元素,有几种取法?
|
|
|
|
|
很明显只有1种取法,就是什么都不取这样一种情况。类似:C(n,0)=C(n,n)=1
|
|
|
|
|
这是递归的base case,如果没有这个1打底,以后再怎么加法原理都是白费
|
|
|
|
|
*/
|
|
|
|
|
for (int i = 1; i < N; i++) c[i][0] = 1, c[i][i] = 1; // base case
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < N; i++)
|
|
|
|
|
for (int j = 1; j < i; j++)
|
|
|
|
|
// 递归式最重要!这是根据数学公式得到的递推式
|
|
|
|
|
// 从递推式由右向左看过去,需要由小到大填充i,j,并且,i>j
|
|
|
|
|
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
init();
|
|
|
|
|
cin >> n;
|
|
|
|
|
while (n--) {
|
|
|
|
|
int a, b;
|
|
|
|
|
cin >> a >> b;
|
|
|
|
|
cout << c[a][b] << endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|