LG5239 回望京都 组合数+暴力

问题描述

LG5239


题解

我就是个傻逼,鉴定完毕。

\(C_m^n=C_{m-1}^n+C_{m-1}^{n-1}\) 都忘了。

所以暴力求出 \(1000\) 以内的 \(C_i^j\) ,二维前缀和即可。


\(\mathrm{Code}\)

#include<bits/stdc++.h>
using namespace std;

const int maxn=1007;
const int mod=19260817;

int T,n,m;
int s[maxn][maxn];
int C[maxn][maxn];


void Init(void){
	scanf("%d",&T);
}

void Preprocess(void){
	C[1][1]=C[1][0]=1;
	for(int i=2;i<=1000;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	for(int i=1;i<=1000;i++){
		for(int j=1;j<=1000;j++){
			s[i][j]=(s[i-1][j]+s[i][j-1]-s[i-1][j-1]+C[i][j]+mod)%mod;
		}
	}
}

void Work(void){
	Preprocess();
	while(T--){
		int n,m;
		scanf("%d%d",&n,&m);
		printf("%d\n",s[m][n]);
	}
}

int main(){
	Init();
	Work();
	return 0;
}
posted @ 2019-12-07 22:56  览遍千秋  阅读(116)  评论(0编辑  收藏  举报