当前位置:网站首页>Deceptive Dice(期望计算)
Deceptive Dice(期望计算)
2022-08-09 20:50:00 【Here_SDUT】
题意
给你一个n个面的骰子,你最多可以投k次,你可以在任意一次停止投掷骰子,并将最后一次的结果作为你的得分,骰子每一面出现的概率均等,让你求最多投k次得分的期望为多少。
分析
我们以20面的骰子最多投3次为例:
只投掷一次: 每一面出现的概率都是\frac{1}{20},再乘上每种情况的得分,可得:\frac{1}{20} * \sum^{20}_{i= 1}{i} = 10.5
最多投两次: 投一次的期望是10.5分,所以只有第一次得分低于10.5才进行第二次投掷,故分为投一次和投两次的情况,投一次的期望为:\frac{1}{20} * \sum_{i=11}^{20}i,投两次的期望可以看成在第一次投掷结果为1-10的前提下,再投一次,即第一次投掷结果为1-10的概率乘上只投掷一次的期望。综上,公式为:\frac{1}{20} * \sum_{i=11}^{20}i+\frac{10}{20} * 10.5 = 13
最多投三次: 投两次的期望为13,那么第一次如果投掷的结果为1-13,那么投掷两次肯定更优,故可以分为两种情况考虑:第一次投掷结果为14-20,那么只要投一次,期望为:\frac{1}{20} * \sum_{i=14}^{20}i;第一次结果为1-13,那么还需要继续投掷,可以看成在第一次投掷结果为1-13的基础上最多投掷两次的期望,即:\frac{13}{20} * 13
可以发现,每次的结果都是由上一步推得,可以得出一个递推关系,那么求n
面骰子,投k
次只要从1
次一直推到k
次即可,由于要用到区间和,用前缀和预处理一下即可,代码实现简单。
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
double s[110];
LL n, k;
int main() {
scanf("%lld %lld", &n, &k);
for (LL i = 1; i <= n; i++) {
s[i] = s[i - 1] + i;
}
double t = s[n] / n;
for (LL i = 2; i <= k; i++) {
LL pos = (LL)t;
t = (s[n] - s[pos]) / n + (pos)*t / n;
}
printf("%.8lf\n", t);
return 0;
}
边栏推荐
- SQL语句及索引的优化
- Beat the interviewer, the CURD system can also make technical content
- fixed investment fund
- 倍福CX5120实现温度控制例程详细解析
- Unity_平滑移动
- Number of daffodils within a thousand
- LoRa无线技术在物联网应用市场的概况和发展
- What to do if Windows 11 can't find Internet Explorer
- Definition and Basic Operations of Linear Tables
- 企业数据打通有什么好处?不同行业怎么解决数据打通难题?
猜你喜欢
力扣15-三数之和——HashSet&双指针法
微软word怎么转换成pdf文件?微软word转换为pdf格式的方法
DSPE-PEG-Silane,DSPE-PEG-SIL,磷脂-聚乙二醇-硅烷修饰二氧化硅颗粒用
URL Protocol 网页打开应用程序
Cholesterol-PEG-Thiol, CLS-PEG-SH, Cholesterol-PEG-Sulfhydryl for improved solubility
【图文并茂】如何进行Win7系统的重装
Prometheus Operator 自定义监控添加redis explorer
微软Excel表格点击单元格行和列都显示颜色怎么弄?聚光灯效果设置
Word怎么制作双面席卡?使用Word制作双面席卡方法
What to do if Windows 11 can't find Internet Explorer
随机推荐
Ali Ermi: Without accept, can a TCP connection be established?
自监督学习 —— MoCo v2
【Efficient Tools】Remote Control Software ToDesk (Favorites)
不经意传输协议OT
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
Problems with compiling SIP with QGIS
Byte side: Can TCP and UDP use the same port?
Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
微软Excel表格点击单元格行和列都显示颜色怎么弄?聚光灯效果设置
如何在WPF中设置Grid ColumnDefinitions的样式
cadence中复制一部分PCB到另一个PCB中去
[Graphic and textual] How to reinstall Win7 system
什么是源文件?
Skywalking系列学习之Trace Profiling源码分析
安科瑞无线物联网智能电表ADW300指导性技术要求-Susie 周
windos安装Mysql8.0,及解决重新登录异常问题 ERROR 1045 (28000)
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
Simulation of Water Temperature Control System Based on Fuzzy PID Controller
Access control knowledge
Unity_平滑移动