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 ...
随机推荐
- 亿级Web系统搭建:单机到分布式集群
亿级Web系统搭建:单机到分布式集群 当一个Web系统从日访问量10万逐步增长到1000万,甚至超过1亿的过程中,Web系统承受的压力会越来越大,在这个过程中,我们会遇到很多的问题.为了解决这些性能压 ...
- Windows cmd 命令行基本操作
Windows cmd 命令行基本操作 1. 进入到指定根目录 注意:不区分大小写 例如进入到 D 盘 2. 进入到指定的目录 例如 (如果目录文件名太长,可以使用 tab 键来自动补全.重复按可以进 ...
- 前端3 — js — BOM没完( 不了解也行 )
1.js是什么? -- 英文全称javascript javaScript(简称"JS") 是一种具有函数优先的轻量级,解释型或即时编译型的编程语言.虽然它是作为开发Web页面的脚 ...
- 学习java的第十七天
一.今日收获 1.java完全学习手册第三章算法的3.1比较值 2.看哔哩哔哩上的教学视频 二.今日问题 1.在第一个最大值程序运行时经常报错. 2.哔哩哔哩教学视频的一些术语不太理解,还需要了解 三 ...
- linux 常用查看命令
linux 常用查看命令 目录 linux 常用查看命令 linux 查看内存/进程-ps/top linux 查看磁盘存储-df linux 查看io读写-iotop linux 查看端口占用-ne ...
- 学习java 7.16
学习内容: 线程安全的类 Lock锁 生产者消费者模式 Object类的等待唤醒方法 明天内容: 网络编程 通信程序 遇到问题: 无
- A Child's History of England.20
CHAPTER 7 ENGLAND UNDER HAROLD THE SECOND, AND CONQUERED BY THE NORMANS Harold was crowned King of E ...
- WebService学习总览
[1]WebService简介 https://blog.csdn.net/xtayfjpk/article/details/12256663 [2]CXF中Web服务请求处理流程 https://b ...
- ZooKeeper 06 - ZooKeeper 的常用命令
目录 1 - 服务端常用命令 2 - 客户端常用命令 3 - 常用四字命令 4 - ZooKeeper 日志的可视化 版权声明 若要部署 ZooKeeper 单机环境,请查看此篇:https://ww ...
- C#文件操作(IO流 摘抄)
11 文件操作概述 11.1 驱动器 在Windows操作系统中,存储介质统称为驱动器,硬盘由于可以划分为多个区域,每一个区域称为一个驱动器..NET Framework提供DriveInfo类和 D ...