B - Discovering Gold

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

概率DP:一般求概率是正推,求期望是逆推。
设\(dp[i]\)表示当前位置在\(i\)处到达\(N\)处得到的金币期望,
\(dp[i]=SUM(dp[i+1],dp[i+2]..dp[i+6])/6+a[i]\);
当\(N-i<6\)时,注意特殊处理。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
#define N 110 int main()
{
int T,iCase=;
int n,a[N];
double dp[N];
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=n;i>=;i--)
{
dp[i]=a[i];
double t=;
int d=min(,n-i);
if(d<=) continue;
for(int j=;j<=d;j++)
{
t+=dp[i+j];
}
dp[i]+=t/d;
}
printf("Case %d: ",iCase++);
printf("%.10f\n",dp[]);
}
return ;
}

[LOJ 1030] Discovering Gold的更多相关文章

  1. LightOJ - 1030 Discovering Gold —— 期望

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

  2. 1030 - Discovering Gold

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

  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+数学期望)

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

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

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

  6. Light OJ 1030 - Discovering Gold(概率dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...

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

  8. LightOJ 1030 Discovering Gold(期望 概率)

    正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / ...

  9. Light OJ 1030 - Discovering Gold

    题目大意: 给你一个1*N的方格,你初始位置是在1,给你一个骰子,假设你现在的位置是X,你投掷一个骰子掷的点数是y, 那么你的新位置就是 X+y, 并且你可以得到新位置的宝藏.假如X+y > N ...

随机推荐

  1. (转载)直接用SQL语句把DBF导入SQLServer

    告诉大家一个直接用SQL语句把DBF导入SQLServer,以及txt导入Access的方法,大家抛弃BatchMove吧来自:碧血剑告诉你一个最快的方法,用SQLServer连接DBF在SQLSer ...

  2. WPF简单入门总结

    WPF简单总结 最近看了点关于WPF的东西,总结了点点入门的东西. XAML语法基础 1.  定义样式 <Window.Resources><!--窗体资源的定义--> < ...

  3. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  4. 地形图比例尺、等高距和DEM分辨率关系

    地表面的形态是很复杂的,不同地貌类型的形态是由它的相对高度、地面坡度以及所处的地势所决定的,它们是影响等高距的主要因素。从等高距计算公式可以看出,当地图比例尺和图上等高线间的最小距离简称等高线间距确定 ...

  5. Java 多线程 简单实例 (Runnable)

    1.多线程实例 package second; public class A implements Runnable { public char stat = '*'; public void run ...

  6. EXTJS 4.2 资料 控件之Window窗体添加html

    //这里要跳转页面 var subWindow = new Ext.Window({ title: '窗口', width: width, height: height, modal: true,// ...

  7. 【学习总结】【多线程】 多线程概要 & GDC & NSOperation

    基本需要知道的 :  进程 :  简单点来说就是,操作系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在受保护的内存空间内 线程 :  一个进程(进程)想执行任务,必须有线程(所以, ...

  8. C#设计模式学习资料--外观模式

    http://www.cf17.com/html/article/172.html http://blog.csdn.net/scucj/article/details/1374657 http:// ...

  9. iis7、mvc2.0 文件上传配置方案

    http://blog.csdn.net/useruse/article/details/5602495

  10. asp.net web api 开发时应当注意的事项

    Self referencing when returning chain of objects. This can be solved using a design pattern called t ...