原题解链接:https://ac.nowcoder.com/discuss/153563
概率。
设为第天下雨的真正概率,由于第i天的概率只与第天有关,所以有
复杂度:加上求逆元的复杂度,
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
LL w[100005], p[100005], T[100005], n, a, b, P;
LL fast_pow(LL a,LL b) {
LL res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main () {
scanf("%lld%lld%lld", &n, &a, &b);
P = 1ll * a * fast_pow(b, mod - 2) % mod;
for (int i = 1; i <= n; ++i) scanf("%lld", &w[i]);
for (int i = 1; i <= n; ++i) {
scanf("%lld%lld", &a, &b);
p[i] = a * fast_pow(b, mod - 2) % mod;
}
T[1] = p[1];
for (int i = 2; i <= n; ++i) {
T[i] += T[i - 1] * ((p[i] + P) % mod) % mod;
T[i] += (1 - T[i - 1] + mod) % mod * p[i] % mod;
T[i] %= mod;
}
LL ans = 0;
for (int i = 1; i <= n; ++i) {
ans += 1ll * T[i] * w[i] % mod;
ans %= mod;
}
cout << ans;
return 0;
}