Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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

Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice after throwing, you add X to your position and collect all the gold from the new position. If your new position is outside the cave, then you keep throwing again until you get a suitable result. When you reach the Nth position you stop your journey. Now you are given the information about the cave, you have to find out the expected number of gold you can collect using the given procedure.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains a blank line and an integer N (1 ≤ N ≤ 100) denoting the dimension of the cave. The next line contains N space separated integers. The ith integer of this line denotes the amount of gold you will get if you come to the ith cell. You may safely assume that all the given integers will be non-negative and no integer will be greater than 1000.

Output

For each case, print the case number and the expected number of gold you will collect. Errors less than 10-6 will be ignored.

Sample Input

3

1

101

2

10 3

3

3 6 9

Sample Output

Case 1: 101.0000000000

Case 2: 13.000

Case 3: 15

题意:走到某个点时就掷一个6面骰子,掷到几就在向前走几步,走到的点宝藏就能拿走,最后要求数学期望

做法:那么这个点的期望dp[i] = dp[i  +1] /6  + dp[i + 2] / 6 + dp[i + 3] /6 + dp[i + 4] / 6 + dp[i + 5] / 6 + dp[i + 6] / 6 + dp[i];

对于小于6的点另做处理

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 210
#define INF 0x3f3f3f3f double a[N], dp[N]; int main()
{
int T, n, cas=1;
scanf("%d", &T); while(T--)
{
scanf("%d", &n);
memset(dp, 0, sizeof(dp));
for(int i=0; i<n; i++)
scanf("%lf", &a[i]); dp[n-1]=a[n-1];
for(int i=n-2; i>=0; i--)
{
dp[i]=a[i];
int t=6;
if(n-1-i<6)
t=n-1-i;
for(int j=1; j<=t; j++)
dp[i]+=dp[i+j]/t;
}
printf("Case %d: %.10f\n", cas++, dp[0]);
}
return 0 ;
}

LightOJ 1030 数学期望的更多相关文章

  1. LightOJ - 1027 数学期望

    题意:有n扇门,每扇门有一个值x,大于0代表x分钟后出去,小于0代表x分钟后回到原地,求出去的时间的期望 题解:假设出去的总时间为sum1,回来的总时间为sum2,出去的门个数为out,进来的门的个数 ...

  2. (LightOJ 1030)期望dp

    You are x N grid. Each cell of the cave can contain any amount of gold. Initially you are . Now each ...

  3. 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 ...

  4. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  5. [BZOJ 3143][HNOI2013]游走(数学期望)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋 ...

  6. Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)

    题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...

  7. 数学期望和概率DP题目泛做(为了对应AD的课件)

    题1: Uva 1636 Headshot 题目大意: 给出一个000111序列,注意实际上是环状的.问是0出现的概率大,还是当前是0,下一个还是0的概率大. 问题比较简单,注意比较大小: A/C & ...

  8. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  9. 【BZOJ2134】单位错选(数学期望,动态规划)

    [BZOJ2134]单位错选(数学期望,动态规划) 题面 BZOJ 题解 单独考虑相邻的两道题目的概率就好了 没了呀.. #include<iostream> #include<cs ...

  10. 【BZOJ1415】【NOI2005】聪聪和可可(动态规划,数学期望)

    [BZOJ1415][NOI2005]聪聪和可可(动态规划,数学期望) 题面 BZOJ 题解 先预处理出当可可在某个点,聪聪在某个点时 聪聪会往哪里走 然后记忆化搜索一下就好了 #include< ...

随机推荐

  1. MybatisPlus自定义枚举映射

    1.问题的由来 在平时开发中多多少少肯定会遇到一些例如status...等特殊含义的字段值,虽然传递10:ADMIN,20:NORMAL可以解决业务需求,但是不是很直观 2.使用MP自定义枚举解决 U ...

  2. Spring中Bean的加载方式~

    1.方式一:基于spring.xml方式配置Bean user import lombok.Data; /** * @author : ly */ @Data public class User { ...

  3. POJ1006、hdu1370

    思路:中国剩余定理.纯粹的用暴力求逆元. 1 #include<iostream> 2 #include<string.h> 3 #include<string> ...

  4. flask中使用pyjwt

    **pyjwt使用教程: ** https://pyjwt.readthedocs.io/en/stable/ 使用案例 import datetime from flask import Flask ...

  5. MinIO客户端之ls

    MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc ls 列出本地硬盘上的文件,命令如下: ./mc ls 控制台的输出,如下: [2023-12-14 23: ...

  6. Ubuntu 命令使用方法

    apt-get 用作于deb包 yum作用于tar包(也可以运作于rpm包) 首先用yum list wget检查一下你的虚拟机有没有安装wget,如果安装了下面图中会显示 @dvd ,我的没有安装所 ...

  7. Java的特性、内容和环境的配置

    Java的特性和优势 简单性 面向对象 可移植性 高性能 分布式 动态性 多线程 安全性 健壮性 JDK包含JRE包含JVM JDK:Java Development Kit JRE:Java Run ...

  8. 如何使用loki查询日志中大于某一数字的值的日志

    简介 loki是一款轻量级的日志收集中间件,比elk体系占用的内存更小,采用go语言开发,可以利用grafana来查询loki中存储的日志,loki存储日志只对提前预设的标签做索引,所以日志存储空间占 ...

  9. 如何通过Python将JSON格式文件导入redis?

    摘要:如果希望将 JSON 文件导入到 Redis 中,首先要做的就是连接到 redis 服务. 本文分享自华为云社区<Python将JSON格式文件导入 redis,多种方法>,作者: ...

  10. 亿级日活业务稳如磐石,华为云CodeArts PerfTest发布

    摘要:近日,华为云性能测试服务CodeArts PerfTest全新上线,提供低门槛.低成本的一站式云化性能测试解决方案. 本文分享自华为云社区<亿级日活业务稳如磐石,华为云CodeArts P ...