牛客2018多校第九场 E Music Game

 链接:https://www.nowcoder.com/acm/contest/147/E
来源:牛客网
 

Niuniu likes to play OSU!

We simplify the game OSU to the following problem.

Given n and m, there are n clicks. Each click may success or fail.

For a continuous success sequence with length X, the player can score X^m.

The probability that the i-th click success is p[i]/100.

We want to know the expectation of score.

As the result might be very large (and not integral), you only need to output the result mod 1000000007.

输入描述:

The first line contains two integers, which are n and m.
The second line contains n integers. The i-th integer is p[i].

1 <= n <= 1000
1 <= m <= 1000
0 <= p[i] <= 100

输出描述:

You should output an integer, which is the answer.

示例1

输入

复制

3 4
50 50 50

输出

复制

750000020

说明

000 0
001 1
010 1
011 16
100 1
101 2
110 16
111 81

The exact answer is (0 + 1 + 1 + 16 + 1 + 2 + 16 + 81) / 8 = 59/4.
As 750000020 * 4 mod 1000000007 = 59
You should output 750000020.

备注:

If you don't know how to output a fraction mod 1000000007,
You may have a look at https://en.wikipedia.org/wiki/Modular_multiplicative_inverse
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1010;
const ll mo=1e9+7;
ll n,m,k;
ll a[maxn],dp[maxn][maxn],sum[maxn][maxn];
ll c[maxn];
ll ans,ct,cnt,tmp,flag;
ll power(ll a,ll n)   //a的n次方mod
{
    ll ans=1;
    a=a%mo;
    while (n)
    {
        if(n&1) ans=(ans*a)%mo;
        n>>=1;
        a=(a*a)%mo;
        }
    return ans;
}
int main()
{
    int T,cas=1;
    while(scanf("%lld %lld",&n,&m)!=EOF)
    {
        c[1]=1;
        for(int i=2;i<=1000;i++) c[i]=power(i,m);
        ans=0;
        tmp=power(100,mo-2);
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }
        a[0]=a[n+1]=0;
        for(int i=1;i<=n;i++)
        {
            dp[i][i-1]=1;
            for(int j=i;j<=n;j++)
            {
                dp[i][j]=dp[i][j-1]*a[j]%mo*tmp%mo;
                ans=(ans+dp[i][j]*(100-a[i-1])%mo*tmp%mo*(100-a[j+1])%mo*tmp%mo*c[j-i+1]%mo)%mo;
            }
        }
        ans=(ans+mo)%mo;
        printf("%lld\n",ans);
      //  if(flag) puts("Yes"); else puts("No");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37748451/article/details/81749147
今日推荐