'commit'
This commit is contained in:
36
TangDou/LuoGuBook/P2822_1.cpp
Normal file
36
TangDou/LuoGuBook/P2822_1.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user