n方预处理组合数,O(1)查询
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;
const int N = 2010, mod = 1e9 + 7;
int n;
int C[N][N];
int main()
{
IOS
cin >> n;
C[0][0] = 1;
for(int i = 1; i <= 2000; i ++)
{
for(int j = 0; j <= i; j ++)
{
if(!j)C[i][j] = 1;
else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
}
while(n --)
{
int a, b;
cin >> a >> b;
cout << C[a][b] << endl;
}
return 0;
}