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

Initially you are in position . Now each turn you throw a perfect  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 (≤ ), denoting the number of test cases. Each case contains a blank line and an integer N ( ≤ N ≤ ) 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 . Output
For each case, print the case number and the expected number of gold you will collect. Errors less than - will be ignored. Sample Input
Output for Sample Input Case : 101.0000000000
Case : 13.000
Case :

题意:

方法:

#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a));
const int oo = 0x3f3f3f3f;
const int N = ;
double dp[N];
int a[N];
int main()
{
int t,n,con=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
met(dp,);
dp[]=;
for(int i=;i<=n;i++)
{
int k=max(i-,);
for(int j=k;j<i;j++)
{
double y=(j>=n-?(n-j):);
dp[i]+=dp[j]/y;
}
}
double sum=;
for(int i=;i<=n;i++)
sum+=dp[i]*a[i];
printf("Case %d: %.10f\n",con++,sum);
}
return ;
}

(LightOJ 1030)期望dp的更多相关文章

  1. LightOJ - 1030 期望+dp

    题目链接:https://vjudge.net/problem/25907/origin 一个山洞,里面有有1到n个位置,每个位置都有一定的金币,你有一个六面的骰子,一开始你在1,每次摇到了哪个数就往 ...

  2. lightoj 1030 概率dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 #include<cstdio> #include<cstri ...

  3. lightOJ 1030(期望)

    题意:有一个迷宫是1×n的格子,一个人每到一个格子就能够把这个格子内的金子所有拿走,刚開始站在第1个格子,然后開始掷骰子得到点数x,他就要从当前位置走到加x的位置.假设发现位置是大于n的就又一次掷骰子 ...

  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. LightOj:1030-Discovering Gold(期望dp模板)

    传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...

  6. LightOJ 1248 Dice (III) (期望DP / 几何分布)

    题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...

  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. Light oj 1030 概率DP

    D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768 ...

  9. 概率dp+期望dp 题目列表(一)

    表示对概率和期望还不是很清楚定义. 目前暂时只知道概率正推,期望逆推,然后概率*某个数值=期望. 为什么期望是逆推的,例如你求到某一个点的概率我们可以求得,然后我们只要运用dp从1~n每次都加下去就好 ...

  10. LightOJ 1364 树形DP

    52张扑克牌,问拿到指定数量的4个花色的最少次数期望是多少,其中拿到joker必须马上将其视作一种花色,且要使后续期望最小. 转移很容易想到,主要是两张joker的处理,一个状态除了普通的4个方向的转 ...

随机推荐

  1. 运算符优先级 (Transact-SQL)

    当一个复杂的表达式有多个运算符时,运算符优先级决定执行运算的先后次序. 执行的顺序可能严重地影响所得到的值. 运算符的优先级别如下表中所示. 在较低级别的运算符之前先对较高级别的运算符进行求值.

  2. Docker系列(四)Dockerfile

    基本语法 使用 #来注释 FROM 指令告诉Docker使用哪个镜像作为基础 接着是维护者信息 RUN 开头的指令会在创建中运行,比如安装软件包 FROM 格式: FROM<image>或 ...

  3. Mac中下载JDK手动更新出现“只支持10.7.3以上的系统版本”问题解决方案

    今天倒腾Hadoop,要修改源码,由于之前搞研究是基于hadoop1.0.3来做的,所以这次也用的这个版本,但是我电脑上Java的版本是1.8以上的,结果用ant编译hadoop源码报错,错误大概是这 ...

  4. POJ-3648 Wedding 2sat

    题目链接:http://poj.org/problem?id=3648‘ 题意:一对情人举行婚礼,有n对夫妇参加,别人对着坐在一个长桌子的两边,新娘和新郎坐在最后面,新娘只能看见坐在他对面的人.现在, ...

  5. win7 下恢复“经典任务栏”/“快速启动栏”,关闭“窗口自动最大化” -摘自网络

    1.自动放大窗口 鼠标把窗口拖到屏幕边缘时,win7会自做聪明的把窗口放大,有时候这个很烦人. 解决办法: 运行“REGEDIT”打开注册表,找到 “HKEY_CURRENT_USER\Control ...

  6. A Tour of Go If

    The if statement looks as it does in C or Java, except that the ( ) are gone and the { } are require ...

  7. A Tour of Go Basic types

    Go's basic types are bool string int int8 int16 int32 int64 uint uint8 uint16 uint32 uint64 uintptr ...

  8. jq问题处理

    1.同一个事件,点击显示和隐藏 $(document).ready(function(){ $('.container .nav-header').click(function(){ var chan ...

  9. C# 读取 timestamp 时间戳 值为byte[] 类型时转换为时间戳字符串

    C# 中如何读取出来的时间戳为 byte[] 类型的话,用以下方式转换成 16进制字符串 string tmpUfts = "0x"+ BitConverter.ToString( ...

  10. J2EE 全面简介

    原文地址:http://www.ibm.com/developerworks/cn/java/j2ee/ J2EE的概念 目前,Java 2平台有3个版本,它们是适用于小型设备和智能卡的Java 2平 ...