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. A - I'm bored with life

    Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university ...

  2. Median Value

    Problem A: Median Value Time Limit: 1 Sec Memory Limit: 128 MB Submit: 874 Solved: 307 [Submit][Stat ...

  3. JEECMS9.3集成dubbo操作记录

    需求描述: 门户及其他应用系统需要查询JEECMS9.3中发布的栏目及数据,而其他系统都是基于dubbo开发的,因此想要将JEECMS9.3中集成dubbo并对外提供内容管理服务. 需求实现: 1.添 ...

  4. MyEclipse去除不必要的validation

    MyEclipse在构建项目时去除不必要的Valication可以加快构建速度. 操作: Window->Perferences->MyEclipse->Validation 在Va ...

  5. L 裁纸片 贪心 + 模拟

    https://biancheng.love/contest-ng/index.html#/123/problems 如果只是输出最小的值,那么好办,a升序,b降序,这样是最优的. 但是需要次数,这就 ...

  6. iOS 中集成海康威视 摄像视频

    本文原文地址  http://www.cnblogs.com/qianLL/p/6652104.html 一.要导入相关的库,注意 这里比较坑的是 要用和他一样的 如果开始的工程中用了AFN或者MJE ...

  7. git + git flow 的简单介绍

    1.git简单实用 git:是一种分布式版本控制系统,因为其优秀的特性个人十分推崇. 1.1设置本机用户身份 git config -global user.name "userName&q ...

  8. web页面打印--铺满A4

    css <style type="text/css"> body { margin: 0; padding: 0; background-color: #FAFAFA; ...

  9. 高仿人人网客户端Android版项目源码

    高仿人人网客户端,有兴趣的盆友可以研究下,里面主要包含的一些UI设计与交互.(注:项目中有少许问题,apk能运行,希望开发者可以参考代码研究一下.) 源码下载:http://code.662p.com ...

  10. swift 使用计算属性+结构管理内存

    class GooClass { deinit { print("aaaaaaaa") } var str = "gooClass" } struct GooS ...