D - 期望

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

Submit Status

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-6will 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

解题思路:

这题要倒着推,由N推向1
设d[k]为到达k这个位置时得到金币的期望,m为该点和N这个位置的距离,a[k]为k这个位置的金币数,因为走的位置不能超过N,所以要取min(m,6)
那么d[k] = 1 / min(m,6) * (d[k + 1] + dp[k+2] + … + d[min(m,6)]) + a[k]

程序代码:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,a[];
double d[];
void init()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
}
void work()
{
memset(d,,sizeof(d));
d[n]=a[n];
for(int i=n-;i>=;i--)
{
d[i]=a[i];
int k=min(,n-i);
for(int j=;j<=k;j++)
d[i]+=d[i+j]*(1.0/k);
} }
int main()
{
int t,Case=;
scanf("%d",&t);
while(t--)
{
init();
work();
printf("Case %d: %.10lf\n",++Case,d[]);
}
return ;
}

数学概念——D 期望的更多相关文章

  1. 数学概念——E 期望(经典问题)

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

  2. 21副GIF动图让你了解各种数学概念

    baidu 21副GIF动图让你了解各种数学概念

  3. 转:21副GIF动图让你了解各种数学概念

    21副GIF动图让你了解各种数学概念

  4. Math concepts / 数学概念

    链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...

  5. slot游戏中的数学概念

    最近研究slot 算法,看了大量的英文资料,因为母语中文,一直使用中文的英文小白来说,好心塞,悔不当初没学好英文. 下文是从众多的英文中摘录的唯一能够看明白的概念.先给自己留着,到时候深入研究可以看 ...

  6. 数学概念 z

    数学是很难的科学,但因为它是科学家用数学来解释宇宙的语言,我们无可避免的要学习它.看看下面的这些 GIF 动图,它们提供了视觉的方式来帮助你理解各种数学技巧. 1.椭圆的画法 2.杨辉三角问题(Pas ...

  7. 数学概念——F 概率(经典问题)birthday paradox

    F - 概率(经典问题) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  8. 21副GIF动图让你了解各种数学概念(转。太强大了)

    “让我们面对它:总的来说数学是不容易的,但当你征服了问题,并达到新的理解高度,这就是它给你的回报.” ——Danica McKellar 数学是很难的科学,但因为它是科学家用数学来解释宇宙的语言,我们 ...

  9. 数学&动态规划:期望DP

    BZOJ3036 给定一张有向无环图,起点为1,终点为N,每个点i有ki条出边,从每个点走其中一条出边的概率是1/ki,求从1到N的期望步数 我们注意到一点,走每条边都是等概率的,那么就相当于 给定一 ...

随机推荐

  1. IntelliJ IDEA 14

    新接触IntelliJ IDEA 14,使用起来还不是很称手,每天在使用中学习吧. 每学到一个新技能就来更新一下. (2015.11.17) " Ctrl + / " 代码批量注释 ...

  2. js的MVC结构设计

    基于jquery的Deferred,设计出如下MVC架构. 模型model interface.js interface: function(userid){ var dtd = $.Deferred ...

  3. .Net framework.

    Figure 1 - .Net Framework The Common Language Runtime (CLR) is the mechanism through which .NET code ...

  4. php利用smtp类轻松的发送电子邮件

    当你还在纠结php内置的mail()函数不能发送邮件时,那么你现在很幸运,此时的这篇文章可以帮助到你! php利用smtp类来发邮件真是屡试不爽,我用过很久了,基本上没出过问题.本博客后台,当博主回复 ...

  5. [转]MySQL数据库备份和还原的常用命令小结

    MySQL数据库备份和还原的常用命令小结,学习mysql的朋友可以参考下: 备份MySQL数据库的命令 mysqldump -hhostname -uusername -ppassword datab ...

  6. javascript常用内置对象总结(重要)

    Javascript对象总结 JS中内置了17个对象,常用的是Array对象.Date对象.正则表达式对象.string对象.Global对象 Array对象中常用方法: Concat():表示把几个 ...

  7. MySQL中删除重复数据只保留一条

    用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 SELECT ...

  8. PHP之验证码识别

    首先推荐几篇有关验证码识别的文章,觉得不错 php实现验证码的识别(初级篇) 关于bp神经网格识别验证码 一.思路 碰见一个验证码,如果我们想要识别它,我们需要的是做什么呢? 我们先观察几个验证码.. ...

  9. 理解CSS Clip属性及用法

    应用Clip属性实现的一个简单效果图: 样式写法: .my-element { position: absolute; clip: rect(10px  350px  170px  0); /* IE ...

  10. A题 - A + B Problem

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Cal ...