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 expectednumber 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

题意:从洞穴的第一点出发,开始掷骰子(六面),掷到的数字是多少就走多少步,每走一步,便会等到那个地点的财宝,最后求得到财宝的期望值

如:

1

101

期望=101*1=101

2

10 3

期望=10*1+3*1=13

3

3 6 9

期望=3*1+(6+9)*0.5+9*0.5=15

#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int maxn=;
int v[maxn];
double dp[maxn];
int main()
{
int T,n,ca=;
cin>>T;
while(T--)
{
cin>>n;
for(int i=;i<=n;i++) cin>>v[i]; memset(dp,,sizeof(dp));
dp[n]=v[n];
for(int j=n-;j>=;j--)
{
dp[j]=v[j];
int cc=min(,n-j);
for(int k=;k<=cc;k++)
{
dp[j]+=dp[j+k]*(1.0/cc);
}
}
printf("Case %d: %f\n",++ca,dp[]);
}
return ;
}

集训第六周 古典概型 期望 D题 Discovering Gold 期望的更多相关文章

  1. 集训第六周 古典概型 期望 C题

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30728 一个立体方块,每个单位方块都是关闭状态,每次任两个点,以这两点为对角 ...

  2. 集训第六周 数学概念与方法 J题 数论,质因数分解

    Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...

  3. LightOj-1030 Discovering Gold (期望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 ...

  4. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...

  5. CF Gym 100187B A Lot of Joy (古典概型)

    题意:给两个一样的只含有26个小写字母的字符串,然后两个分别做一下排列,问如果对应位置的字母相等那么就愉悦值就加一,问愉悦值的期望是多少? 题解:只考虑两个序列相对的位置,那么就相当于固定一个位置,另 ...

  6. 集训第六周 E题

    E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  7. python数学第四天【古典概型】

  8. 集训第六周 O题

    Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...

  9. 集训第六周 M题

    Description   During the early stages of the Manhattan Project, the dangers of the new radioctive ma ...

随机推荐

  1. 一个 Java 对象到底有多大?

    阅读本文大概需要 2.8 分钟. 出处:http://u6.gg/swLPg 编写 Java 代码的时候,大多数情况下,我们很少关注一个 Java 对象究竟有多大(占据多少内存),更多的是关注业务与逻 ...

  2. 51nod 1098 最小方差

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ty ...

  3. Floyd+限制路径步数(快速幂优化)

    POJ 3613 Cow Relays 最短路可以采用Floyd来计算,但是限制时间在1s内,估计直接写会超时,所以要用到快速幂来优化. 快速幂的思想是:xy=xy/2∗2" role=&q ...

  4. 题解报告:hdu 1062 Text Reverse

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 Problem Description Ignatius likes to write word ...

  5. ORACLE数据库的备份分为物理备份和逻辑备份两种。

    物理备份是将实际组成数据库的操作系统文件从一处拷贝到另一处的备份过程,通常是从磁盘到磁带.可以使用 Oracle 的恢复管理器(Recovery Manager,RMAN)或操作系统命令进行数据库的物 ...

  6. 222 Count Complete Tree Nodes 完全二叉树的节点个数

    给出一个完全二叉树,求出该树的节点个数.完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置.若最底层为第 h ...

  7. jQuery幸运大转盘_jQuery+PHP抽奖程序

    http://www.thinkphp.cn/code/1153.html 网上转盘抽奖程序大多是flash完成的,而本文使用jQuery和PHP来实现转盘抽奖程序. 若是想看更多js特效.网站源码. ...

  8. redis的安装使用以及一些常用的命令

    Redis是一个key-value存储系统.并提供多种语言的API,我们可使用它构建高性能,可扩展的Web应用程序.目前越来越多的网站用它来当做缓存,减轻服务器的压力. 本文安装用的到redis是绿色 ...

  9. AJPFX理解反射及反射的应用

    怎么理解反射,反射的应用        反射就是把Java类中的各种成分映射成相应的Java类.        一般情况下我们要解决某个问题,先找到相关的类,创建该类的对象,然后通过该对象调用对应的方 ...

  10. 如何看Spring源码

    想要深入的熟悉了解Spring源码,我觉得第一步就是要有一个能跑起来的极尽简单的框架,下面我就教大家搭建一个最简单的Spring框架,而且是基于Java Config形式的零配置Spring框架. 首 ...