链接: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]/.
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 .
输入描述:
The first line contains two integers, which are n and m.
The second line contains n integers. The i-th integer is p[i]. <= n <=
<= m <=
<= p[i] <=
输出描述:
You should output an integer, which is the answer.
示例1
输入 复制 输出 复制 说明 The exact answer is ( + + + + + + + ) / = /.
As * mod =
You should output .
备注:
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

解题思路:

我们假设一场游戏的一个子情况是0111011011,那么这个对结果的贡献是(3^m+2^m+2^m)*P(这种情况发生的概率)

将此式拆开==> 3^m*P+2^m*P+2^m*P

我们考虑3^m*P这部分,等价于3^m*P1*P2(P1为前五个点为01110的概率,P2为后面为11011的概率),然后我们想一下,求最后的期望值,要算出所有的情况,那么其中就会有一些前五个点为01110的情况,那么这部分的和就为3^m*P1*(sum(p2,p3,p4......)),而sum(p2,p3,p4......)这部分等于1,因为后面的点将会发生所有情况,那么概率为1。而这只是算前五个点位01110的情况,我们还要算0110和11...和其他子情况的一段1,那么计算过程和上面是一样的,所以最后的结果就是将所有的连续1的序列的贡献求出来,累加一下就是答案。

如果你还是不懂

我给你举个例子:

0 0  | 0 1       q1*q2*q3*p4

1 0  | 0 1       p1*q2*q3*p4

1 1  | 0 1       p1*p2*q3*p4

0 1  |  0 1      q1*p2*q3*p4

此时遍历到最后一位是个1,这样前一位保证是0 ,对于有这种组合的所有数已经如上图排列,我们会发现其他地方即前两位是全排列,所以算这种情况的全排列的时候,(q1*q2+p1*q2+p1*p2+q1*p2)*q3*p4 ,括号内的值为1,所以这种情况的期望值就是1-n枚举连续1的情况。前一位和后一位为0的状态

#include<iostream>
#include<stdio.h>
using namespace std;
#define ll long long
const int mod =1e9+;
ll qsm(ll a,ll b)
{
ll ans=;
while(b>)
{
if(b%==)
{
ans=ans*a%mod;
}
b=b/;
a=a*a%mod;
}
return ans;
}
ll gailv1[];
ll gailv2[];
ll f[];
ll dp[][];
int main()
{
ll n,m;
scanf("%lld%lld",&n,&m);
ll inv=qsm(,mod-);
for(int i=;i<=n;i++)
{
scanf("%lld",&gailv1[i]);
gailv2[i]=(-gailv1[i])*inv%mod;
gailv1[i]=gailv1[i]*inv%mod; } for(int i=;i<=n;i++)
{
f[i]=qsm(i,m);
} gailv2[]=*inv%mod;
gailv2[n+]=*inv%mod;
for(int i=;i<=n;i++)
{
dp[i][i]=gailv1[i];
for(int j=i+;j<=n;j++)
dp[i][j]=dp[i][j-]*gailv1[j]%mod;
}
ll ans=;
for(int i=;i<=n;i++)
for(int j=i;j<=n;j++)
{ ans=(ans+dp[i][j]*f[j-i+]%mod*gailv2[i-]%mod*gailv2[j+]%mod)%mod;
} cout<<ans<<endl;
return ;
}

牛客网第9场多校E(思维求期望)的更多相关文章

  1. 牛客网第4场A

    链接:https://www.nowcoder.com/acm/contest/142/A 来源:牛客网 题目描述 A ternary , , or . Chiaki has a ternary in ...

  2. 牛客网练习赛34-D-little w and Exchange(思维题)

    链接:https://ac.nowcoder.com/acm/contest/297/D 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  3. 牛客网-2018年全国多校算法寒假训练营练习比赛(第四场)-A

    解题思路:二分图的最大匹配,但这题是所有点都遍历一遍,所以答案/2: 代码: #include<iostream> #include<algorithm> #include&l ...

  4. 2019 牛客网 第七场 H pair

     题目链接:https://ac.nowcoder.com/acm/contest/887/H  题意: 给定A,B,C问在[1,A]和[1,B]中有多少对x,y满足x&y>C或者x^y ...

  5. 牛客网PAT-练兵场-挖掘机技术哪家强

    题目地址:https://www.nowcoder.com/pat/6/problem/4058 题解:用数组下标当学校编号.输入一次数据的时候,直接在相应数组下标位置累加内容,同时更新最大的总分的学 ...

  6. 牛客网小白月赛6C(DFS,思维)

    #include<bits/stdc++.h>using namespace std;vector<int>tree[1000010];int sum=0;int dfs(in ...

  7. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  8. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  9. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

随机推荐

  1. 关于linux系统CPU篇--->上下文切换

    1.什么是CPU上下文切换? linux是一个多任务操作系统,它支持远大于CPU数量的任务同时运行,当然这些任务实际上并不是真的同时在运行,而是因为系统在很短的时间内,将CPU轮流分配给它们,造成多任 ...

  2. kubernetes 开发 code-generator

    主要参考项目 https://github.com/kubernetes/code-generator 1. git clone https://github.com/kubernetes/code- ...

  3. OLTP和OLAP的区别

    OLTP和OLAP的区别 联机事务处理OLTP(on-line transaction processing) 主要是执行基本日常的事务处理,比如数据库记录的增删查改.比如在银行的一笔交易记录,就是一 ...

  4. future then

    import 'dart:async'; main(){ Future(()=>a1()) .then((x)=>a2(x)) .then((x)=>a3(x)) .then((x) ...

  5. Linux启动过程简述

    Linux启动过程: 图片来自:https://www.cnblogs.com/codecc/p/boot.html 简单来讲: 加载BIOS–>读取MBR–>Boot Loader–&g ...

  6. 【spotlight安装监控】

    参考博客: https://www.cnblogs.com/ceshi2016/p/9012646.html http://blog.sina.com.cn/s/blog_1517220f20102x ...

  7. stm32库函数建工程和使用Keil自带库建工程有没有区别?发现了同样的程序在两种情况下keil自带库可以运行的情况,不知是什么原因

    我使用库函数建的工程(非Keil自带库),为了实现SPI对Si24r1芯片数据的读写,以验证stm32是否可以和si24r1能够正常通信,发现使用库函数建的工程程序不能通过,读出来的数据和写的数据不一 ...

  8. java 反射的简介

    https://blog.csdn.net/sinat_38259539/article/details/71799078

  9. thinkphp3.2升级至thinkphp5.0.24

    view文件 修改文件名 把tp3.2.3\app\module\view文件夹下所有文件夹拷贝至tp5\app\module\view 打开cmd命令窗口,cd至view文件夹下,执行dir /b ...

  10. CentOS设置服务开机启动的两种方法

    一.通过服务的方式设置自启动 1.  在/etc/init.d 下建立相关程序的启动脚本 2.  chkconfig --add mysqld(添加服务到chkconfig列表中) chkconfig ...