1. 程式人生 > 其它 >Monotonic Matrix(lemma定理)

Monotonic Matrix(lemma定理)

技術標籤:寒假集訓

lemma定理:

有n對點(a_{1},b_{1}),(a_{2},b_{2})...(a_{n},b_{n}),設e(a_{i},b_{i})表示a_{i}b_{i}的路徑方案數

則行列式\begin{vmatrix} e(a_{1},b_{1}) & e(a_{1},b_{2}) & ... & e(a_{1},b_{n}) \\ e(a_{2},b_{1}) & e(a_{2},b_{2}) & ... & e(a_{2},b_{n}) \\ ... & ... & ... & ...\\ e(a_{n},b_{1}) & e(a_{n},b_{2}) & ... & e(a_{n},b_{n}) \end{vmatrix}表示a_{i}b_{i}的嚴格不相交路徑的方案數

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int N=2e3+100;
ll fac[N];
ll qp(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return res%mod;
}
ll C(ll n,ll m){
	return fac[n]*qp(fac[m],mod-2)%mod*qp(fac[n-m],mod-2)%mod;
}
void init(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=fac[i-1]*i%mod;
	}
}
int main(){
	ll n,m;
	init();
	while(scanf("%lld%lld",&n,&m)!=EOF){
		printf("%lld\n",(C(n+m,n)*C(n+m,n)%mod-C(n+m,n+1)*C(n+m,n-1)%mod+mod)%mod);
	}
	return 0;
	
}