0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 21:28:48 +00:00

P2822 [NOIP2016 提高组] 组合数问题

https://www.luogu.com.cn/record/80088595
This commit is contained in:
Baoshuo Ren 2022-07-18 15:10:02 +08:00
parent 6fcc52aaf7
commit e318a6bac2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

41
Luogu/P2822/P2822.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2005;
int t, k, n, m, c[N][N], f[N][N];
int main() {
cin >> t >> k;
c[1][1] = 1;
for (int i = 1; i <= 2000; i++) {
c[i][0] = c[i][i] = 1;
}
for (int i = 2; i <= 2000; i++) {
for (int j = 1; j < i; j++) {
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % k;
}
}
for (int i = 1; i <= 2000; i++) {
for (int j = 1; j <= i; j++) {
f[i][j] = f[i][j - 1] + f[i - 1][j] - f[i - 1][j - 1];
if (!c[i][j]) f[i][j]++;
}
f[i][i + 1] = f[i][i];
}
while (t--) {
cin >> n >> m;
cout << f[n][std::min(n, m)] << endl;
}
return 0;
}