题目链接

题意:

  在一个1 X N 的格子上, 每个格子都有一定的黄金, 你从第一个格子出发, 问到最后一个格子得到黄金的期望。

  每次前进使用骰子投点来决定前进步数, 如果投出的点前进后会超过N, 那么就重新投掷。

思路:

  很直接的期望题。

  概率dp求期望是从后往前求, 每次的概率为 1 / 6.

  dp[i] = 1/6 * (dp[i + 1] + dp[i + 2] + dp[i + 3] + dp[i + 4] + dp[i + 5] + dp[i + 6]) + x[i].

  根据投掷的点数加上当前的位置会不会超过N来确定括号里面加的项, 还有概率。

代码:

  

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define MAXN 110
#define MOD 1000000007
#define eps 1e-6
int n;
double dp[MAXN]; int main()
{
int T;
int kcase = ;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
for(int i = ; i <= n; i ++)
scanf("%lf", &dp[i]);
for(int i = n - ; i >= ; i --)
{
if((n - i) >= )
for(int j = ; j <= ; j ++)
dp[i] += dp[i + j] / 6.0;
else
for(int j = ; j <= (n - i); j ++)
dp[i] += dp[i + j] / (double)(n - i);
}
printf("Case %d: %.7lf\n", ++ kcase, dp[]);
}
return ;
}

LightOj_1030 Discovering Gold的更多相关文章

  1. [LOJ 1030] Discovering Gold

    B - Discovering Gold Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  2. LightOJ - 1030 Discovering Gold —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold    PDF (English) Statistics For ...

  3. 1030 - Discovering Gold

    1030 - Discovering Gold    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 M ...

  4. LightOJ 1030 Discovering Gold(期望)

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

  5. LightOJ 1030 - Discovering Gold - [概率DP]

    题目链接:https://cn.vjudge.net/problem/LightOJ-1030 You are in a cave, a long cave! The cave can be repr ...

  6. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  7. Discovering Gold LightOJ - 1030 (概率dp)

    You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave c ...

  8. Discovering Gold LightOJ - 1030 || 概率与期望求法区别

    #include<cstdio>//wrong_codes #include<algorithm> using namespace std; ],anss; ],T,TT,n, ...

  9. 集训第六周 古典概型 期望 D题 Discovering Gold 期望

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

随机推荐

  1. MyEclipse10搭建Strust2开发环境

    一.创建一个JavaWeb项目 启动MyEclipse10    ,然后在MyEclipse中创建一个JavaWeb项目,点击[File]---->[New]---->[WebProjec ...

  2. [Machine Learning (Andrew NG courses)]II. Linear Regression with One Variable

  3. Block使用变量,让你的程序看起来清晰!

    <span style="font-size:24px;">为什么要使用block变量呢? 由于当我们的程序比較繁杂的时候,我们在一个函数中要调用一个函数,还须要在外边 ...

  4. gdb调试运行时的程序小技巧

    使用gdb调试运行时的程序小技巧 标签: 未分类 gdb pstack | 发表时间:2012-10-15 04:32 | 作者:士豪 分享到: 出处:http://rdc.taobao.com/bl ...

  5. 编写跨平台代码之memory alignment

    编写网络包(存储在堆上)转换程序时,在hp-ux机器上运行时会遇到 si_code: 1 - BUS_ADRALN - Invalid address alignment. Please refer ...

  6. 深入理解iframe

    本文并不是一篇iframe API文档讲解,因此想了解iframe API的同学请移步 MDN, 我将在现在浏览器的角度与大家取探讨iframe, 因此,本文中虽然会提及一些iframe在旧浏览器中的 ...

  7. jQuery Validate 插件

    >>>>>>>>>>>>>>>>>>>>>>>>> ...

  8. Android canvas rotate():平移旋转坐标系至任意原点任意角度-------附:android反三角函数小结

    自然状态下,坐标系以屏幕左上角为原点,向右是x正轴,向下是y正轴.现在要使坐标系的原点平移至任一点O(x,y),且旋转a角度,如何实现? 交待下我的问题背景,已知屏幕上有两点p1和p2,构成直线l.我 ...

  9. (转)JS获取当前对象大小以及屏幕分辨率等

    Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...

  10. mysql连接错误:Cannot get hostname for your address

    问题 环境:win7 + 64Bit + 本地mysql5.6 问题:navicat连接本地mysql数据库,提示“Cannot get hostname for your address”,但是连接 ...