比赛 |
2022级数学专题练习赛7 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
组合数问题 |
最终得分 |
100 |
用户昵称 |
op_组撒头屯 |
运行时间 |
1.254 s |
代码语言 |
C++ |
内存使用 |
36.40 MiB |
提交时间 |
2023-01-30 19:06:48 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define qi queue<int>
#define sti stack<int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=2000+5;
int c[N][N],d[N][N];
int main(){
freopen ("problem.in","r",stdin);
freopen ("problem.out","w",stdout);
int T,k;scanf("%d%d",&T,&k);
c[0][0]=1;
for (int i=1;i<=2000;i++){
c[i][0]=1;
for (int j=1;j<=i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%k;
}
for (int i=0;i<=2000;i++){
for (int j=0;j<=i;j++){
d[i][j]=(c[i][j]%k==0);
if (i)d[i][j]+=d[i-1][j];
if (j)d[i][j]+=d[i][j-1];
if (i&&j)d[i][j]-=d[i-1][j-1];
}
d[i][i+1]=d[i][i];
}
while(T--){
int n,m;scanf("%d%d",&n,&m);
printf("%d\n",d[n][min(n,m)]);
}
return 0;
}