牛客网第9场多校E(思维求期望)
链接: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(思维求期望)的更多相关文章
- 牛客网第4场A
链接:https://www.nowcoder.com/acm/contest/142/A 来源:牛客网 题目描述 A ternary , , or . Chiaki has a ternary in ...
- 牛客网练习赛34-D-little w and Exchange(思维题)
链接:https://ac.nowcoder.com/acm/contest/297/D 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- 牛客网-2018年全国多校算法寒假训练营练习比赛(第四场)-A
解题思路:二分图的最大匹配,但这题是所有点都遍历一遍,所以答案/2: 代码: #include<iostream> #include<algorithm> #include&l ...
- 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 ...
- 牛客网PAT-练兵场-挖掘机技术哪家强
题目地址:https://www.nowcoder.com/pat/6/problem/4058 题解:用数组下标当学校编号.输入一次数据的时候,直接在相应数组下标位置累加内容,同时更新最大的总分的学 ...
- 牛客网小白月赛6C(DFS,思维)
#include<bits/stdc++.h>using namespace std;vector<int>tree[1000010];int sum=0;int dfs(in ...
- 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)
链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...
- 牛客网暑期ACM多校训练营(第五场):F - take
链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
随机推荐
- git 本地提交代码到 github 远程库,没有弹框 github login
git 本地提交代码到 github 远程库,没有弹框 github login: 原因: win10 有个凭据管理器,给保存了历史登陆用户名密码,导致无法切换用户. 解决办法: 删除历史登陆用户 ...
- liunx驱动----USB驱动
现象:把usb设备接入电脑 1.Windows发现设备 2.跳出一个对话框提示安装驱动程序 问1:既然没有驱动程序,为什么了够知道是什么驱动了?? 答1:Windows里面已经有了usb总线驱动程序, ...
- Python数据分析Pandas库之熊猫(10分钟一)
pandas熊猫10分钟教程 排序 df.sort_index(axis=0/1,ascending=False/True) df.sort_values(by='列名') import numpy ...
- 【ubuntu】-桌面假死的解决办法
第一,通过ctrl+art+F1(1-6),启动本地终端 切换到了字符界面tty1 第二,查询进程,ps -e |grep tty7 得到tty7的pid号 第三,杀死tty7的进程 , kill 9 ...
- 兼容ie8总结
最近做了个兼容ie8的项目,把遇到的一些坑总结一下,欢迎大神指正,共勉. 一. js相关 1. 关于库的引用 jquery只能引用1.x的版本,swiper只能引用2.x的版本. 2. 动态生成的d ...
- mysql中的内置函数
这里主要介绍mysql丰富的内置函数. 数学函数 数学函数相对比较简单,就是涉及一些数值的计算,这里列出数学函数的功能,仅个别给出实例. 函数 作 用 ABX(x) 返回x的绝对值 CEIL(X),C ...
- ASUS RT-N16 使用OpenWrt 安装 ss记录
本文用于记录一下使用ASUS RT-N16 使用OpenWrt 安装 shadowsocks的过程. 前后一共折腾了一个星期,原先使用的是tomato固件,但是在配置iptables的过程中,执行 r ...
- knative
office Doc Knative 简介 Install sevice example (knative) There is only one node in the cluster so we u ...
- spring-IoC的配置文件applicationContext.XML
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- MVC模式和Django中的MVT模式
MVC模式:是一种程序设计模式,其核心思想是分工.解耦,让不同的代码块之间降低耦合,增强代码的可扩展性和可移植性,实现向后兼容. MVC:Model-View-Control M:主要封装对数据库层的 ...