牛客网多校赛第9场 E-Music Game【概率期望】【逆元】
链接:https://www.nowcoder.com/acm/contest/147/E
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
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
感觉最近需要好好补一下数学方面的题目包括概率期望什么的 平时接触的太少了
看题解说要用什么第二类斯特林数 什么玩意啊 根本没听过 多校赛到处都是别人很熟的而我们听都没听过的东西
但是看了一下别的题解其实也没有那么难吧
顺便学习了一下分数取模的方法
一个数a乘一个数b对p取模 和a乘b的逆元对p取模结果是一样的
求逆元最方便的方法是用扩展欧几里得
https://blog.csdn.net/stray_lambs/article/details/52133141这篇博客讲欧几里得讲的还是蛮细的
但是我还是没有很明白题解里求的inv 是什么道理
下面说说题目的主体思路
首先用快速幂预处理得分
用pos[i][j]表示从 i 到 j 这段区间全部是获胜的概率
pos[i][j]肯定是可以有pos[i][j - 1]推出来的
枚举i , j 表示从i + 1 到 j - 1都连续胜利利用期望的可加性E(X+Y)=E(X)+E(Y);
这段的期望就是(i失败的概率)*(j失败的概率)*(i-j连续获胜的概率)*(分数)
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
#define inf 1e18
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1005;
long long m, n, p[maxn];
long long ipowm[maxn], pos[maxn][maxn];
long long qpow(long long x, long long m)
{
long long ans = 1;
while(m){
if(m & 1){
ans = ans * x % mod;
}
x = x * x % mod;
m = m >> 1;
}
return ans;
}
long long exgcd(long long a, long long b, long long &x, long long &y)
{
if(a == 0 && b == 0)
return -1;
if(b == 0){
x = 1;
y = 0;
return a;
}
long long d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
//扩展欧几里得求逆元 用于分数取模
long long mod_rev(long long a, long long n)
{
long long x, y;
long long d = exgcd(a, n, x, y);
if(d == 1)
return (x % n + n) % n;
else return -1;
}
int main()
{
long long inv = mod_rev(100ll, mod);//因为这里概率还要除以100,所以第一个参数写100, 第二个参数就是模
//cout<<inv;
while(scanf("%lld%lld", &n, &m) != EOF){
//cout<<1;
for(int i = 1; i <= n; i++){
scanf("%lld", &p[i]);
ipowm[i] = qpow(i, m);
}
//cout<<1;
p[0] = p[n + 1] = 0;
long long ans = 0;
for(int i = 1; i <= n; i++){
pos[i][i] = p[i] * inv % mod;
for(int j = i + 1; j <= n; j++){
pos[i][j] = pos[i][j - 1] * p[j] % mod * inv % mod;
}
}
for(int i = 0; i <= n; i++){
for(int j = i + 2; j <= n + 1; j++){
ans += pos[i + 1][j - 1] * ipowm[j - i - 1] % mod
* (100 - p[i]) % mod * inv % mod * (100 - p[j]) % mod * inv % mod;
ans %= mod;
}
}
printf("%lld\n", ans);
}
return 0;
}
牛客网多校赛第9场 E-Music Game【概率期望】【逆元】的更多相关文章
- 牛客网多校赛第七场J--Sudoku Subrectangle
链接:https://www.nowcoder.com/acm/contest/145/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6553 ...
- 牛客网多校赛第七场--C Bit Compression【位运算】【暴力】
链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网多校赛第七场A--Minimum Cost Perfect Matching【位运算】【规律】
链接:https://www.nowcoder.com/acm/contest/145/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网-湘潭大学校赛重现H题 (线段树 染色问题)
链接:https://www.nowcoder.com/acm/contest/105/H来源:牛客网 n个桶按顺序排列,我们用1~n给桶标号.有两种操作: 1 l r c 区间[l,r]中的每个桶中 ...
- 牛客网多校赛第九场A-circulant matrix【数论】
链接:https://www.nowcoder.com/acm/contest/147/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...
- 牛客网多校训练第四场C sequence
(牛客场场有笛卡尔树,场场都不会用笛卡尔树...自闭,补题心得) 题目链接:https://ac.nowcoder.com/acm/contest/884/C 题意:给出两个序列a,b,求max{mi ...
- 牛客网多校训练第三场 C - Shuffle Cards(Splay / rope)
链接: https://www.nowcoder.com/acm/contest/141/C 题意: 给出一个n个元素的序列(1,2,...,n)和m个操作(1≤n,m≤1e5),每个操作给出两个数p ...
- 牛客网多校训练第三场 A - PACM Team(01背包变形 + 记录方案)
链接: https://www.nowcoder.com/acm/contest/141/A 题意: 有n(1≤n≤36)个物品,每个物品有四种代价pi,ai,ci,mi,价值为gi(0≤pi,ai, ...
- 牛客网多校训练第八场A All one Matrix
题目链接:https://ac.nowcoder.com/acm/contest/888/A 题意:求出有多少个不被包含的全1子矩阵 解题思路:首先对列做处理,维护每个位置向上1的个数,然后我们从最后 ...
随机推荐
- Linux服务器部署 Elasticsearch 成功,本机却访问不了
Elasticsearch版本: elasticsearch- 服务器版本: CentOS release 6.8 (Final) 问题: Linux服务器上部署了 Elasticsearch 5.5 ...
- instsrv.exe srvany.exe启动服务
1.通过注册表注册服务 private static readonly string regpath = @"SYSTEM\CurrentControlSet\Services\Consul ...
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String'
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ' ...
- 浅谈PostgreSQL的索引
1. 索引的特性 1.1 加快条件的检索的特性 当表数据量越来越大时查询速度会下降,在表的条件字段上使用索引,快速定位到可能满足条件的记录,不需要遍历所有记录. create table t(id i ...
- 【权限维持】window服务端常见后门技术
0x00 前言 未知攻焉知防,攻击者在获取服务器权限后,通常会用一些后门技术来维持服务器权限,服务器一旦被植入后门,攻击者如入无人之境.这里整理一些window服务端常见的后门技术,了解攻击者的常见后 ...
- 怎么打乱List中元素的顺序
使用Collections类中shuffle随机打乱List内部元素顺序 原文地址:http://blog.csdn.net/warren2013/article/details/17414771 / ...
- Selenium 基本用法
如下,使用 Selenium 打开淘宝首页并获取页面源代码: from selenium import webdriver browser = webdriver.Chrome() # 声明一个浏览器 ...
- CentOS7--su和sudo
在某些情况下, 以root用户身份访问系统有潜在危险,并可能导致系统和数据损害.我们可以用setuid程序,例如su和sudo解决. su命令 [app01rot@app-01 ~]$ su - ro ...
- 清理和关闭多余的Windows 7系统服务
清理和关闭多余的Windows 7系统服务 现在已经有不少配置不是很高的电脑用户正式用上了Windows 7(以下简称Win 7),如何让低配置电脑可以更流畅的运行Win 7呢?虽然部分软件提供了傻瓜 ...
- USACO The Clocks
操作间没有次序关系,同一个操作最多重复3次... 可以直接暴力... The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 ...