链接: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
#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