集训第六周 古典概型 期望 D题 Discovering Gold 期望
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 expectednumber 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
题意:从洞穴的第一点出发,开始掷骰子(六面),掷到的数字是多少就走多少步,每走一步,便会等到那个地点的财宝,最后求得到财宝的期望值
如:
1
101
期望=101*1=101
2
10 3
期望=10*1+3*1=13
3
3 6 9
期望=3*1+(6+9)*0.5+9*0.5=15
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int maxn=;
int v[maxn];
double dp[maxn];
int main()
{
int T,n,ca=;
cin>>T;
while(T--)
{
cin>>n;
for(int i=;i<=n;i++) cin>>v[i]; memset(dp,,sizeof(dp));
dp[n]=v[n];
for(int j=n-;j>=;j--)
{
dp[j]=v[j];
int cc=min(,n-j);
for(int k=;k<=cc;k++)
{
dp[j]+=dp[j+k]*(1.0/cc);
}
}
printf("Case %d: %f\n",++ca,dp[]);
}
return ;
}
集训第六周 古典概型 期望 D题 Discovering Gold 期望的更多相关文章
- 集训第六周 古典概型 期望 C题
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=30728 一个立体方块,每个单位方块都是关闭状态,每次任两个点,以这两点为对角 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- LightOj-1030 Discovering Gold (期望DP)
You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave c ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- CF Gym 100187B A Lot of Joy (古典概型)
题意:给两个一样的只含有26个小写字母的字符串,然后两个分别做一下排列,问如果对应位置的字母相等那么就愉悦值就加一,问愉悦值的期望是多少? 题解:只考虑两个序列相对的位置,那么就相当于固定一个位置,另 ...
- 集训第六周 E题
E - 期望(经典问题) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- python数学第四天【古典概型】
- 集训第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 集训第六周 M题
Description During the early stages of the Manhattan Project, the dangers of the new radioctive ma ...
随机推荐
- Luogu P1541 乌龟棋 【线性dp】
题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行 N 个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第 N 格是终点,游戏要求玩家控制一个乌龟 ...
- 利用动态扫描和定时器1在数码管上显示出从765432开始以1/10秒的速度往下递减 直至765398并保持此数,与此同时利用定时器0以500MS速度进行流水灯从上至下移动 ,当数码管上数减到停止时,实验板上流水灯出停止然后全部开始闪烁,3秒后(用 T0定时)流水灯全部关闭,数码管上显示出“HELLO”,到此保持住
#include <reg52.h> #include <intrins.h> #define uchar unsigned char #define uint unsigne ...
- CAD中的文本编排操作
AutoCAD中导入超文本实现方法 除了AutoCAD内含的文本输入命令外,向AutoCAD中输入多行文本即超文本的方法还有:通过Windows提供的剪贴板,利用AutoCAD提供的多行文本命 ...
- 1.1.1最短路(Floyd、Dijstra、BellmanFord)
转载自hr_whisper大佬的博客 [ 一.Dijkstra 比较详细的迪杰斯特拉算法讲解传送门 Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算 ...
- Oracle查看所有表空间的数据使用情况
-- 查看所有表空间的数据使用情况 SELECT Upper(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)& ...
- D. Winter Is Coming 贪心(好题)
http://codeforces.com/contest/747/problem/D 大概的思路就是找到所有两个负数夹着的线段,优先覆盖最小的长度.使得那时候不用换鞋,是最优的. 但是这里有个坑点, ...
- Tcpdump的用法
见 超级详细Tcpdump 的用法 http://www.itshouce.com.cn/linux/linux-tcpdump.html
- Solr和Spring Data Solr
一.Solr概述与安装 1.Solr简介 Solr是一个开源搜索平台,用于构建搜索应用程序. 它建立在Lucene(全文搜索引擎)之上. Solr是企业级的,快速的和高度可扩展的.Solr可以和Had ...
- 关于 user agent ua
1.ua介绍: ua查询参考网址:http://www.atool.org/useragent.php(也可以自己制作html查询) js 属性:navigator.userAgent 使用方法:将网 ...
- mysql 字段包含某个字符的函数
通过sql查询语句,查询某个字段中包含特定字符串: 例子:查询e_book表的types字段包含字符串"3",有下面4种方式 select * from e_book where ...