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.

37 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2010; //n的数值上限
int t; //t次查询
int n; //n个数字中
int m; //找m个数字组合
int K; //给定k求k的倍数
int C[N][N]; //组合数数组
int main() {
cin >> t >> k;
//预处理杨辉三角形
for (int i = 0; i < N; i++) {
//base case
C[i][0] = C[i][i] = 1; //组合数C(n,0)=1 组合数C(n,n)=c(n,0)=1
//递推生成其它组合数
for (int j = 1; j < i; j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % k;
}
//处理t次询问
while (t--) {
int ans = 0;
cin >> n >> m;
//这是最朴素的方法,但每次计算,性能差,因为询问次数多,每次都现从头计算,
//不是离线计算,是在线计算,不适合多次询问这一方式,可以考虑采用某一种方法进行离线计算就好了。
//这时就需要引入二维前缀和否则有两个点TLE只会得90分。
for (int i = 1; i <= n; i++)
for (int j = 1; j <= min(i, m); j++)
if (!C[i][j]) ans++;
cout << ans << endl;
}
}