牛客网多校赛第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静态库生成
Linux上的静态库,其实是目标文件的归档文件. 在Linux上创建静态库的步骤如下: 写源文件,通过 gcc -c xxx.c 生成目标文件. 用 ar 归档目标文件,生成静态库. 配合静态库,写一 ...
- Linux+Redis实战教程_day02_2、redis简述及安装与启动
2. redis简述及安装 关系型数据库(SQL): Mysql,oracle 特点:数据和数据之间,表和字段之间,表和表之间是存在关系的 例如:部门表 001部门, 员工表 001 用户表,用户 ...
- iOS 严重问题解释(crash)
问题1:Exception Type: 00000020 Exception Codes: 0x000000008badf00d Exception Note: SIMULATED (this is ...
- RFC文件
RFC(Request For Comments)-意即“请求评议”,包含了关于Internet的几乎所有重要的文字资料.如果你想成为网络方面的专家,那么RFC无疑是最重要也是最经常需要用到的资料之一 ...
- PHP代码审计笔记--CSRF漏洞
0x01 前言 CSRF(Cross-site request forgery)跨站请求伪造.攻击者盗用了你的身份,以你的名义向第三方网站发送恶意请求,对服务器来说这个请求是完全合法的,但是却完成了攻 ...
- WAF Bypass数据库特性(Mysql探索篇)
0x01 背景 Mysql数据库特性探索,探索能够绕过WAF的数据库特性. 0x02 测试 常见有5个位置即: SELECT * FROM admin WHERE username = 1[位置一 ...
- 使用 urllib 解析 URL 链接
urllib 库还提供了 parse 模块,它定义了处理 URL 的标准接口,例如实现 URL 各部分的抽取.合并以及链接转换,常用的方法如下: In []: from urllib.parse im ...
- SpringMVC系列之主要组件
一.组件说明 DispatcherServlet:前端控制器,用于请求到达前端控制器,由它调用其他组件处理用户的请求. HandlerMapping:处理器映射器,负责根据用户请求找到Handler( ...
- C++多线程编程简单实例
C++本身并没有提供任何多线程机制,但是在windows下,我们可以调用SDK win32 api来编写多线程的程序,下面就此简单的讲一下: 创建线程的函数 HANDLE CreateThread( ...
- Glide加载图片缓存库出现——You cannot start a load for a destroyed activity
请记住一句话:不要再非主线程里面使用Glide加载图片,如果真的使用了,请把context参数换成getApplicationContext.