[LOJ 1030] 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的更多相关文章
- LightOJ - 1030 Discovering Gold —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold PDF (English) Statistics For ...
- 1030 - Discovering Gold
1030 - Discovering Gold PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 M ...
- 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 ...
- LightOj 1030 - Discovering Gold(dp+数学期望)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...
- LightOJ 1030 Discovering Gold (概率/期望DP)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- Light OJ 1030 - Discovering Gold(概率dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...
- 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 ...
- LightOJ 1030 Discovering Gold(期望 概率)
正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / ...
- Light OJ 1030 - Discovering Gold
题目大意: 给你一个1*N的方格,你初始位置是在1,给你一个骰子,假设你现在的位置是X,你投掷一个骰子掷的点数是y, 那么你的新位置就是 X+y, 并且你可以得到新位置的宝藏.假如X+y > N ...
随机推荐
- 处理部分WordPress核心代码或功能,让你的网站更快
处理部分WordPress核心代码或功能,让你的网站更快 http://www.wpdaxue.com/speed-up-wordpress.html
- nodejs的模块系统(实例分析exprots和module.exprots)
前言:工欲善其事,必先利其器.模块系统是nodejs组织管理代码的利器也是调用第三方代码的途径,本文将详细讲解nodejs的模块系统.在文章最后实例分析一下exprots和module.exprots ...
- W25Q32的使用
一.W25Q32简介 W25Q32是华邦公司推出的大容量“SPI FLASH” 产品. 1.容量 32M-Bit/4M-byte(4,194,304) 2.存储结构 页:256-bytes 扇区:4 ...
- 关于Oracle数据库中SQL空值排序的问题
在Oracle中进行查询排序时,如果排序字段里面有空值的情况下,排序结果可能会达不到自己想要的结果. 如 select * from tableTest order by VISITS desc ...
- HDFS入门详解
一. 前提和设计目标 1. 硬件错误是常态,因此需要冗余,这是深入到HDFS骨头里面去了 HDFS可能由成百上千的服务器所构成,每个服务器上存储着文件系统的部分数据.我们面对的现实是构成系统的组件数目 ...
- hdu 4101
比赛的时候先是受以前一个圣神海的题目 用了两遍DFS 第一遍标记出围墙 第二遍求围墙外和每块围墙降为1所需的攻击次数 结果爆栈 改为BFS后AC DFS的加了一句这个 #pragma comme ...
- hdu 3631
最短路 执行一遍 Floyd算法 比赛的时候没有想到, 用了优化的Dijkstra 超时到死 #include <cstdio> #include <cstring> ...
- POJ 3761 Bubble Sort(乘方取模)
点我看题目 题意 : 冒泡排序的原理众所周知,需要扫描很多遍.而现在是求1到n的各种排列中,需要扫描k遍就变为有序的数列的个数,结果模20100713,当然了,只要数列有序就扫描结束,不需要像真正的冒 ...
- windows中断与共享的连接(samba)
问题:window下当成功登录到samba服务器上的共享的目录的时候,若要是再系想登录此服务器上另外一个共享目录时,会弹出登录窗口. 但是不管输入的用户名和密码对错都会提示. “不允许一个用户使用一个 ...
- linux 配置java环境变量
修改/etc/profile文件 如果你的计算机仅仅作为开发使用时推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,可能会给系统带来安全性问题. ·用文本编辑器打开/etc/profi ...