题意:

现在一共有n天,第i天如果有流星雨的话,会有wi颗流星雨。
第1天有流星雨的概率是p1。
如果第i−1 (i≥2)天有流星雨,第i天有流星雨的可能性是pi+P,否则是pi。
求n天后,流星雨颗数的期望。
分数以逆元形式输出
 
思路:
直接在逆元情况下做
第i天有流星雨的概率为t[i]=t[i-1]*(p[i-1]+P)+(1-t[i-1])*p[i]
注意减法的时候要加mod
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);
ll fp(ll a,ll n){
ll ans = ;
while(n){
if(n&)ans*=a;
n>>=;
a*=a;
a%=mod;
ans%=mod;
}
return ans;
}
ll f[maxn],t[maxn],w[maxn];
ll p;
int main() {
ll n, a, b;
scanf("%lld %lld %lld", &n, &a, &b);
p = a*fp(b,mod-)%mod;
for(int i = ; i <=n; i++){
scanf("%lld", &w[i]);
}
for(int i = ; i <= n; i++){
scanf("%lld %lld", &a, &b);
f[i] = a*fp(b,mod-)%mod;
}
ll tmp = ;
ll ans = f[]*w[]%mod;
t[]=f[];
for(int i = ; i <= n; i++){
t[i] += t[i-]*(f[i]+p)%mod+(-t[i-]+mod)*f[i]%mod;
t[i]%=mod;
ans+=t[i]*w[i]%mod;
ans%=mod;
}
printf("%lld",ans);
return ;
}

牛客练习赛39 C 流星雨 (概率dp)的更多相关文章

  1. 牛客练习赛26B 烟花 (概率DP)

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

  2. 牛客练习赛52 | C | [烹饪] (DP,裴蜀定理,gcd)

    牛客练习赛52 C 烹饪 链接:https://ac.nowcoder.com/acm/contest/1084/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 327 ...

  3. 牛客练习赛39 B:选点(二叉树遍历+LIS)

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

  4. 牛客练习赛39 B.选点

    链接:https://ac.nowcoder.com/acm/contest/368/B 来源:牛客网 题目描述 有一棵n个节点的二叉树,1为根节点,每个节点有一个值wi.现在要选出尽量多的点. 对于 ...

  5. 牛客练习赛69 火柴排队 题解(dp)

    题目链接 题目大意 给你一个长为n(n<=5e3)的数组a.随机使得k个元素增加d.要你求多大的概率使得,这些数组元素的相对大小不发生改变 输出 n 行每行一个整数,第 i 行的整数表示 k=i ...

  6. 牛客练习赛37-筱玛的字符串-DP递推

    筱玛的字符串 思路 :dp [ i ] [ j ] [ 3 ] 分别代表到第 i 位时 左括号比右括号多 j ,后面有三个状态 分别表示当前位置 S3的字符 是正在反转的,还是 反转完成的,还是没有反 ...

  7. 牛客练习赛71 数学考试 题解(dp)

    题目链接 题目大意 要你求出有多少个长度为n的排列满足m个限制条件 第i个限制条件 p[i]表示前 p[i]个数不能是1-p[i]的排列 题目思路 这个感觉是dp但是不知道怎么dp 首先就是要明白如果 ...

  8. 牛客练习赛71 C.数学考试 (DP,容斥原理)

    题意:RT 题解:先对\(p\)排个序,然后设\(dp[i]\)表示前\(i-1\)个\(p[i]\)满足条件但是\(p[i]\)不满足,即在\([1,p[i]]\)中不存在从\(p[1]\)到\(p ...

  9. 牛客练习赛39 D 动态连通块+并查集 X bitset 优化

    https://ac.nowcoder.com/acm/contest/368/D 题意 小T有n个点,每个点可能是黑色的,可能是白色的.小T对这张图的定义了白连通块和黑连通块:白连通块:图中一个点集 ...

随机推荐

  1. k8s-整体概述和架构

    1.Kubernetes是什么 Kubernetes是一个轻便的和可扩展的开源平台,用于管理容器化应用和服务.通过Kubernetes能够进行应用的自动化部署和扩缩容.在Kubernetes中,会将组 ...

  2. vue项目使用v-charts的柱形图的各种样式和数据配置

    找了很多网上关于v-charts的柱形图使用,我发现我一模一样的配置就是没有效果,我原来是按需引入的, import VeHistogram from 'v-charts/lib/histogram' ...

  3. C# Datatable 添加列

    DataTable dt = new DataTable("Datas"); DataColumn dc = null; //dt新增列 dc=dt.Columns.Add(&qu ...

  4. JAVA封装、继承、多态

    封装 1.概念: 将类的某些信息隐藏在类的内部,不允许外部程序访问,而是通过该类提供的方法来实现对隐藏信息的操作和访问. 2.好处: a.只能通过规定的方法访问数据 b.隐藏类的实例细节,方便修改和实 ...

  5. vim添加多行注释的几种方式

    最近需要在阿里云上部署项目,不可避免地会遇到vim这个工具,查了一些资料,总结了一下使用vim多行注释的方法 块操作 多行注释: 首先按esc进入命令行模式下,按下Ctrl + v,进入列(也叫区块) ...

  6. python基础操作以及变量运用

    今天学习关于pycharm的操作以及变量的知识 1.关于pycharm的基本操作,作为一个小白,仪式感还是要有 在基础界面上新建然后打印hello world,也是对python的一种尊重吧 2.关于 ...

  7. sg函数的变形 - 可以将一堆石子分开

    Nim is a two-player mathematic game of strategy in which players take turns removing objects from di ...

  8. kafka模式对比

    Receiver是使用Kafka的高层次Consumer API来实现的.receiver从Kafka中获取的数据都是存储在Spark Executor的内存中的,然后Spark Streaming启 ...

  9. 如何选择kmeans中的k值——肘部法则–Elbow Method和轮廓系数–Silhouette Coefficient

    肘部法则–Elbow Method 我们知道k-means是以最小化样本与质点平方误差作为目标函数,将每个簇的质点与簇内样本点的平方距离误差和称为畸变程度(distortions),那么,对于一个簇, ...

  10. Tesseract-OCR-v5.0中文识别,训练自定义字库,提高图片的识别效果

    1,下载安装Tesseract-OCR 安装,链接地址https://digi.bib.uni-mannheim.de/tesseract/ ​ 2,安装成功 tesseract -v 注意:安装后, ...