首页 技术 正文
技术 2022年11月11日
0 收藏 864 点赞 3,317 浏览 2035 个字

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

输入

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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896