2015-2016 ACM-ICPC, Central Europe Regional Contest (CERC 15)F

题意:给你F[1,i]和F[i,1] 接着有递推式F[i, j] = a ∗ F[i, j − 1] + b ∗ F[i − 1, j] + c.让你计算F[n,n]

题解:这题F[1,i]的贡献很显然是\binom{2*n-2-i}{n-2}a^{n-i}b^{n-1}F(1,i),F(i,1)的贡献同理

对于c的贡献我们每个点都计算很显然不好求我们可以做如下操作

\forall i,j\in[1,n]f(x,y) = F(x,y)+d并且f(n,n) = a*f(n,n-1)+b*f(n-1,n)那么

\begin{align*} f(n,n) &= a*f(n,n-1)+b*f(n-1,n)\\ & = a*F(n,n-1)+a*d+b*F(n-1,n)+b*d\\ & = a*F(n,n-1)+b*F(n-1,n)+(a+b)*d\\ F(n,n)+d &= a*F(n,n-1)+b*F(n-1,n)+(a+b)*d\\ (a+b-1)*d &= F(n,n)-a*F(n,n-1)-b*F(n-1,n)\\ c&=(a+b-1)*d\\ d &= \frac{c}{a+b-1} \end{align*}

我们解得f(n,n) = F(n,n)+\frac{c}{a+b-1}并且f(n,n) = a*f(n,n-1)+b*f(n-1,n)那么我们就可以得出以下式子

\begin{align*} f(n,n) &= \sum_{i=2}^{n}\binom{2*n-2-i}{n-2} a^{n-i}b^{n-1}f(1,i)+\sum_{i=2}^{n}\binom{2*n-2-i}{n-2}a^{n-1}b^{n-i}f(i,1)\\ F(n,n)&=f(n,n)-\frac{c}{a+b-1} \end{align*}

然后打个表就可以O(n)计算每个点的贡献

#include 
using namespace std;
typedef long long ll;
const int mx = 2e6+5;
const int mod = 1e6+3;
ll l[mx],t[mx];
ll x[mx],y[mx];
ll inv[mx],fac[mx];
ll modexp(ll x,ll n){
	ll ans = 1;
	while(n){
		if(n&1) ans = ans*x%mod;
		x = x*x%mod;
		n /= 2; 
	}
	return ans;
}
void init(){
	inv[1] = 1;
	fac[1] = 1;
	fac[0] = inv[0] = 1;
	for(int i = 2; i < mx; i++)
		inv[i] = 1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i = 2; i < mx; i++)
		fac[i] = fac[i-1]*i%mod;
	for(int i = 2; i < mx; i++)
		inv[i] = inv[i]*inv[i-1]%mod;
}
ll C(int n,int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	init();
	int n,a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	x[0] = y[0] = 1;
	for(int i = 1; i <= n; i++)
		x[i] = x[i-1]*a%mod,y[i] = y[i-1]*b%mod;
	for(int i = 1; i <= n; i++)
		scanf("%lld",&l[i]),l[i] = (l[i]+c*modexp(a+b-1,mod-2)%mod)%mod;
	for(int i = 1; i <= n; i++)
		scanf("%lld",&t[i]),t[i] = (t[i]+c*modexp(a+b-1,mod-2)%mod)%mod;
	ll ans = 0;
	for(int i = 2; i <= n; i++){
		ans += C(n-2+n-i,n-i)*l[i]%mod*x[n-1]%mod*y[n-i]%mod;
		ans %= mod;
	}
	for(int i = 2; i <= n; i++){
		ans += C(n-2+n-i,n-i)*t[i]%mod*y[n-1]%mod*x[n-i]%mod;
		ans %= mod;	
	}
//	cout<

 

你可能感兴趣的:(数学)