牛客网暑期ACM多校训练营(第九场)E Music Game

概率题,我们先预处理出来每个区间出现的概率,然后记得计算的时候当前区间的前后要乘以失败的概率再乘以区间所能产生的价值(x^m)。最后求一求就结束了。

#include
#include
#include
#include
using namespace std;
#define LL long long int
const int mod = 1e9 + 7;
const int inv = 570000004;
int n, m;
LL p[1010];
LL mpow[1010];
LL pre[1010][1010];
LL Pow(LL a, LL b)
{
    LL res = 1;
    while (b)
    {
        if (b & 1) (res *= a) %= mod;
        (a *= a) %= mod;
        b >>= 1;
    }
    return res;
}
int main()
{
    scanf("%d%d", &n, &m);
    p[0] = p[n + 1] = 0;
    for (int i = 1;i <= n;i++)
        scanf("%d", &p[i]), mpow[i] = Pow(i, m);
    for (int i = 1;i <= n;i++)
    {
        pre[i][i] = p[i] * inv%mod;
        for (int j = i + 1;j <= n;j++)
            pre[i][j] = pre[i][j - 1] * p[j] % mod*inv%mod;
    }
    LL res = 0;
    for (int i = 1;i <= n;i++)
    {
        for (int j = i;j <= n;j++)
        {
            res += pre[i][j] * mpow[j - i+1] % mod*(100 - p[i-1]) % mod*inv%mod*(100 - p[j+1]) % mod*inv%mod;
            res %= mod;
        }
    }
    printf("%lld\n", res);
    return 0;
}

你可能感兴趣的:(多校,牛客)