【CF908D New Year and Arbitrary Arrangement】

【Analysis】

fi,jf_{i,j}表示有ii个A,jj个AB期望长度。目标状态是f1,0f_{1,0},因为f0,0f_{0,0}会转移自己。容易得到方程:
fi,j=papa+pb×fi1,j+pbpa+pb×fi,j+if_{i,j}= \dfrac{pa}{pa+pb} \times f_{i-1,j} + \dfrac{pb}{pa+pb}\times f_{i,j+i}

初始转态是fi,j(i+jk)f_{i,j}(i+j\geqslant k),因为再加一个B就完成了。设期望xx次中一次B,Papapa+pbP_a\gets\dfrac{pa}{pa+pb}Pbpbpa+pbP_b\gets\dfrac{pb}{pa+pb}ci+jc\gets i+j
xPb×i=0(c+i)×Paix\gets P_b \times \sum\limits_{i=0}^{\infty}(c+i)\times P_a^i
设数列{an}\{a_n\}满足an=(c+n)×Pana_n=(c+n)\times P_a^n

Sn=i=0naiS_n=\sum\limits_{i=0}^na_i

Pa×Sn=papa+pb×i=0n(c+i)×papa+pbP_a \times S_n=\dfrac{pa}{pa+pb}\times \sum\limits_{i=0}^n(c+i)\times \dfrac{pa}{pa+pb}

=i=0n(c+i)×(papa+pb)i+1=\sum\limits_{i=0}^n(c+i)\times (\dfrac{pa}{pa+pb})^{i+1}

Pa+Pb=1\because P_a+P_b=1

xlimnPb×Sn=limnSnPa×Sn\therefore x\gets \lim\limits_{n\to\infty}P_b\times S_n=\lim\limits_{n\to\infty}S_n-P_a\times S_n
=limni=0n(c+i)×papa+pbi=0n(c+i)×(papa+pb)i+1=\lim\limits_{n\to\infty} \sum\limits_{i=0}^n(c+i)\times \dfrac{pa}{pa+pb}-\sum\limits_{i=0}^n(c+i)\times (\dfrac{pa}{pa+pb})^{i+1}
=limn(c+0)×Pa0+i=1n(c+i)×Paii=1n(c+i1)×Pai+(c+n)×Pan+1=\lim\limits_{n\to\infty} (c+0)\times P_a^0 + \sum\limits_{i=1}^n(c+i)\times P_a^i-\sum\limits_{i=1}^n(c+i-1)\times P_a^i +(c+n)\times P_a^{n+1}
=limnc+i=1nPai+(c+n)×Pan+1=\lim\limits_{n\to\infty} c+\sum\limits_{i=1}^n P_a^i+(c+n)\times P_a^{n+1}
=limnc+PaPan×Pa1Pa+(c+n)×Pan+1=\lim\limits_{n\to\infty} c+\dfrac{P_a-P_a^n\times P_a}{1-P_a}+(c+n)\times P_a^{n+1}
=limnc+papb×(1Pan)+(c+n)×Pan+1=\lim\limits_{n\to\infty} c+\dfrac{pa}{pb}\times (1-P_a^n)+(c+n)\times P_a^{n+1}
=limnc+papb+(c+n)×Pan+1=\lim\limits_{n\to\infty} c+\dfrac{pa}{pb}+(c+n)\times P_a^{n+1}
=limnc+papb+c+n(pa+pbpa)n+1=\lim\limits_{n\to\infty} c+\dfrac{pa}{pb}+\dfrac{c+n}{(\dfrac{pa+pb}{pa})^{n+1}}
(c+n)n(pa+pbpa)n+1n\because (c+n)随着n的增大单调递增,(\dfrac{pa+pb}{pa})^{n+1}随着n的增大单调递增
\therefore 满足洛必达法则
f(x)g(x)x=a(0/0)(/)f(x)g(x)=f(x)g(x)根据洛必达法则,\dfrac{f(x)}{g(x)}如果在x=a处变成 (0/0)或是(\infty/\infty),那么\dfrac{f(x)}{g(x)}=\dfrac{f^\prime(x)}{g^\prime(x)}
xlimnc+papb+c+n(pa+pbpa)n+1\therefore x\gets \lim\limits_{n\to\infty} c+\dfrac{pa}{pb}+\dfrac{c+n}{(\dfrac{pa+pb}{pa})^{n+1}}
=limnc+papb+1ln(pa+pbpa)×(pa+pbpa)n+1=\lim\limits_{n\to\infty} c+\dfrac{pa}{pb}+\dfrac{1}{\ln(\dfrac{pa+pb}{pa})\times (\dfrac{pa+pb}{pa})^{n+1}}
=c+papb=c+\dfrac{pa}{pb}

时间复杂度Θ(k2)\Theta(k^2)

【Code】

#include <bits/stdc++.h>
using namespace std;
 
typedef long long int64;
const int P = 1e9 + 7;
inline int qPow(int x, int y)
{
	int res = 1, base = x;
	while (y > 0)
	{
		if (y & 1)
			res = 1ll * res * base % P;
		base = 1ll * base * base % P;
		y >>= 1;
	}
	return res;
}
inline int inv(int x) { return qPow(x, P - 2); }
inline int add(int x, int y) { x += y; x -= x >= P ? P : 0; return x; }
inline int mul(int x, int y) { return 1ll * x * y % P; }

int main(void)
{
	int n = 1, a = 1, b = 1;
	cin >> n >> a >> b;
	const int A = 1ll * a * inv(a + b) % P;
	const int B = (1 - A + P) % P;
	const int V = 1ll * a * inv(b) % P;
	vector <vector <int>> dp(n + 1);
	for (int i = 1;i <= n; ++i)
		dp[i].resize(n + 1);
	
	for (int i = n;i >= 1; --i)
		for (int j = n;j >= 0; --j)
			dp[i][j] = (i + j >= n) ? (add(i, add(j, V))) : (add(mul(dp[i + 1][j], A), mul(dp[i][i + j], B)));
	cout << dp[1][0] << '\n';
	return 0;
}
发布了14 篇原创文章 · 获赞 2 · 访问量 1180
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览