1030 - Discovering Gold
| Time Limit: 2 second(s) | Memory Limit: 32 MB |
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 |
Output for Sample Input |
|
3 1 101 2 10 3 3 3 6 9 |
Case 1: 101.0000000000 Case 2: 13.000 Case 3: 15 |
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #include<algorithm>
5 #include<iostream>
6 #include<math.h>
7 #include<queue>
8 #include<stack>
9 using namespace std;
10 double cost[105];
11 double dp[105];
12 int main(void)
13 {
14 int i,j,k;
15 scanf("%d",&k);
16 int s;
17 for(s=1; s<=k; s++)
18 {
19 int n;
20 scanf("%d",&n);
21 for(i=1; i<=n; i++)
22 {
23 scanf("%lf",&cost[i]);
24 }
25 memset(dp,0,sizeof(dp));
26 dp[1]=1;double sum=0;
27 for(i=1;i<=n;i++)
28 {
29 int t=min(i+6,n);
30 for(j=i+1;j<=t;j++)
31 {
32 dp[j]+=1.0*dp[i]/(t-i);
33 }
34 sum+=cost[i]*dp[i];
35 }
36 printf("Case %d: %.10f\n",s,sum);
37 }
38 return 0;
39 }
1030 - Discovering Gold的更多相关文章
- LightOJ - 1030 Discovering Gold —— 期望
题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold PDF (English) Statistics For ...
- [LOJ 1030] Discovering Gold
B - Discovering Gold Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- 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 ...
随机推荐
- Levenshtein莱文斯坦算法在项目中的应用
简介 根据维基百科的描述,在信息理论.语言学和计算机科学中,莱文斯坦距离是一个测量两个序列之间差异的字符串度量.非正式地,两个单词之间的莱文斯坦距离是将一个单词改变为另一个单词所需的最小单字符编辑次数 ...
- 23. 关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
原文:https://blog.csdn.net/u011596455/article/details/60322568 版权声明:本文为博主原创文章,转载请附上博文链接! 在Ubuntu中,有时候运 ...
- Linux常用命令之文件权限管理
Linux文件权限管理1.改变文件或目录的权限:chmod命令详解命令名称:chmod命令所在路径:/bin/chmod执行权限:所有用户语法:chmod [{ugoa}{+-=}{rwx}] [文件 ...
- Linux学习 - 文件包处理命令
一.搜索文件find find [搜索范围] [匹配条件] (1) -name(名字查找) <1> find /etc -name init 查找/etc下以 "in ...
- Classs类
Classs类如何获得 获得Class对象 方式一: 通过Object类中的getClass()方法 方式二: 通过 类名.class 获取到字节码文件对象( 方式三: 通过Class类中的方法(将类 ...
- 【Spark】【复习】Spark入门考前概念相关题复习
Spark考前概念相关题复习 AUthor:萌狼蓝天 哔哩哔哩:萌狼蓝天 博客园:我的文章 - 萌狼蓝天 博客:萌狼工作室 - 萌狼蓝天 (mllt.cc) 选择题 Hadoop 1.HADOOP的三 ...
- [BUUCTF]PWN——wustctf2020_closed
wustctf2020_closed 附件 步骤: 例行检查,64位程序,开启了nx保护 本地试运行一下看看大概的情况 64位ida载入,首先是检索程序里的字符串,找到了后门 main函数里的关键函数 ...
- 保留重复项(Power Query 之 M 语言)
数据源: "姓名""基数""个人比例""个人缴纳""公司比例""公司缴纳"&qu ...
- MyBatis 3学习笔记
MyBatis 3 一.MyBatis简介 优秀的持久层框架,支持支持自定义 SQL.存储过程以及高级映射,专注于SQL的编写. 为什么不使用工具类进行数据库操作: 功能简单,sql语句编写在 ...
- CF1506A Strange Table 题解
Content 给定一个 \(n\times m\) 的矩阵.一开始,\((1,1)\) 所在位置上面的数是 \(1\),随后先由上往下将这一列中的所有位置上面填上 \(2,3,\dots,n\),再 ...