集训第六周 古典概型 期望 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 ...
随机推荐
- POJ2486 Apple Tree 【树上背包】
一句话题意:一棵树,一共n个点,每个点上有一个权值,求从1出发,走k步,最多能遍历到的权值.可以往回走. 第一(二)道树上背包题,先是看了dalao的题解,改了一点就过样例了.然而....TLE??? ...
- 《windows核心编程系列》十六谈谈内存映射文件
内存映射文件允许开发人员预订一块地址空间并为该区域调拨物理存储器,与虚拟内存不同的是,内存映射文件的物理存储器来自磁盘中的文件,而非系统的页交换文件.将文件映射到内存中后,我们就可以在内存中操作他们了 ...
- saltstack实战笔记
#运维管理工具 ansible #支持ssh,不需要客户端 saltstack #也是只是ssh,不需要客户端的 安装架构是,master /minion 安装salt的依赖模块 python zer ...
- [Usaco2017 Feb]Why Did the Cow Cross the Road II (Platinum)
Description Farmer John is continuing to ponder the issue of cows crossing the road through his farm ...
- [ZPG TEST 108] Antimonotonicity【贪心】
T2:Antimonotonicity (Antimonotonicity.pas/in/out 128M 1s) 给你1-N的一个排列,数列中的数字互不相等,要求找出最长的子序列a,满足a1> ...
- 51nod 1068 Bash游戏 V3
列出前几项可以发现是个规律题,不要被题目的文字所欺骗,字符串处理10^1000即可 #include <bits/stdc++.h> using namespace std; int ge ...
- Looper、MessageQueue、Message、Handler的关系
1.快速复习 1.1 基本装置 类 装置名 作用 线程中数量 Looper 消息分发装置 从消息队列中取出一个消息,交给对应的Handler处理消息. 1 MessageQueue 消息队列 保存所有 ...
- 工厂方法模式及php实现
工厂方法模式: 工厂方法模式(Factory Method Pattern)又称为工厂模式,也叫虚拟构造器(Virtual Constructor)模式或者多态工厂(Polymorphic Facto ...
- 2017团体程序设计天梯赛大区赛 L3-3 球队“食物链”
思路: 状压dp. 实现: #include <iostream> #include <cstdio> #include <cstring> using names ...
- Jauery 中Ajax的几种异步请求
以下介绍Jquery中 Post Get Ajax几种异步请求的使用方法 <%@ Page Language="C#" AutoEventWireup=&q ...