Source: Good Bye 2017
Problem:
一个空串,
Pa
的概率往末尾加
a
,
Idea:
dp(i,j)
表示
a
的数量有
当
注意到前缀
b
没有贡献,那么答案就是
Code:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ALL(A) (A).begin(), (A).end()
#define CLR(A, X) memset(A, X, sizeof(A))
typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const double PI = acos(-1.0);
const auto INF = 0x3f3f3f3f;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x<0?-1:1; }
const int MAXN = 1005;
const LL MOD = 1e9+7;
LL dp[MAXN][MAXN];
LL qpow(LL a, LL b) {
LL ret = 1;
while(b) {
if(b&1) ret = ret*a%MOD;
a = a*a%MOD;
b >>= 1;
}
return ret;
}
LL inv(LL t) { return qpow(t, MOD-2); }
int main() {
int n; LL pa, pb;
scanf("%d%lld%lld", &n, &pa, &pb);
LL t = pa+pb;
pa = pa*inv(t)%MOD;
pb = pb*inv(t)%MOD;
LL p = pa*inv(pb)%MOD;
for(int i = n; i >= 0; i--) {
for(int j = n; j >= 0; j--) {
if(i+j >= n) dp[i][j] = (i+j+p)%MOD;
else dp[i][j] = (dp[i+1][j]*pa%MOD+dp[i][i+j]*pb%MOD)%MOD;
}
}
printf("%lld\n", dp[1][0]);
return 0;
}