牛客多校赛第九场 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

有n次点击每次点击成功的概率是p[i]/100,连续点击成功X次会获得X^m的分数,求分数的期望。

题解来源

作者:Cload9
链接:https://www.nowcoder.com/discuss/94910?type=101&order=0&pos=1&page=0
来源:牛客网
 

首先,预处理出每一段一直成功的概率。

然后我们可以枚举i,j表示在[i+1,j-1]区间内成功连击,并且由题目可知要计算上这段分数必须在i,j失败,结束连击,这段的期望就是(i失败的概率)*(j失败的概率)*([i+1,j-1]都成功的概率)。

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll _pow(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
			res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}	
	return res;
}
ll p[1010][1010];
ll q[1010];
ll a[1010];
int main()
{
	ll inv=_pow(100,1000000005);
	ll n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),q[i]=_pow(i,m);
	for(int i=1;i<=n;i++)
	{
		p[i][i]=a[i]*inv%mod;
		for(int j=i+1;j<=n;j++)
			p[i][j]=p[i][j-1]*a[j]%mod*inv%mod;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ans+=p[i+1][j]*q[j-i]%mod*(100-a[i])%mod*inv%mod*(100-a[j+1])%mod*inv%mod;
			ans=ans%mod;
		}
	}
	printf("%lld\n",ans);

	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值