LightOJ 1030 数学期望
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[i] = dp[i +1] /6 + dp[i + 2] / 6 + dp[i + 3] /6 + dp[i + 4] / 6 + dp[i + 5] / 6 + dp[i + 6] / 6 + dp[i];
对于小于6的点另做处理
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 210
#define INF 0x3f3f3f3f double a[N], dp[N]; int main()
{
int T, n, cas=1;
scanf("%d", &T); while(T--)
{
scanf("%d", &n);
memset(dp, 0, sizeof(dp));
for(int i=0; i<n; i++)
scanf("%lf", &a[i]); dp[n-1]=a[n-1];
for(int i=n-2; i>=0; i--)
{
dp[i]=a[i];
int t=6;
if(n-1-i<6)
t=n-1-i;
for(int j=1; j<=t; j++)
dp[i]+=dp[i+j]/t;
}
printf("Case %d: %.10f\n", cas++, dp[0]);
}
return 0 ;
}
LightOJ 1030 数学期望的更多相关文章
- LightOJ - 1027 数学期望
题意:有n扇门,每扇门有一个值x,大于0代表x分钟后出去,小于0代表x分钟后回到原地,求出去的时间的期望 题解:假设出去的总时间为sum1,回来的总时间为sum2,出去的门个数为out,进来的门的个数 ...
- (LightOJ 1030)期望dp
You are x N grid. Each cell of the cave can contain any amount of gold. Initially you are . Now each ...
- 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)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- [BZOJ 3143][HNOI2013]游走(数学期望)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3143 分析: 易得如果知道了每条边经过的数学期望,那就可以贪心着按每条边的期望的大小赋 ...
- Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)
题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...
- 数学期望和概率DP题目泛做(为了对应AD的课件)
题1: Uva 1636 Headshot 题目大意: 给出一个000111序列,注意实际上是环状的.问是0出现的概率大,还是当前是0,下一个还是0的概率大. 问题比较简单,注意比较大小: A/C & ...
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
- 【BZOJ2134】单位错选(数学期望,动态规划)
[BZOJ2134]单位错选(数学期望,动态规划) 题面 BZOJ 题解 单独考虑相邻的两道题目的概率就好了 没了呀.. #include<iostream> #include<cs ...
- 【BZOJ1415】【NOI2005】聪聪和可可(动态规划,数学期望)
[BZOJ1415][NOI2005]聪聪和可可(动态规划,数学期望) 题面 BZOJ 题解 先预处理出当可可在某个点,聪聪在某个点时 聪聪会往哪里走 然后记忆化搜索一下就好了 #include< ...
随机推荐
- 【纯手工打造】时间戳转换工具(python)
1.背景 最近发现一个事情,如果日志中的时间戳,需要我们转换成时间,增加可读性.或者将时间转换成时间戳,来配置时间.相信大多人和我一样,都是打开网页,搜索在线时间戳转换工具,然后复制粘贴进去.个人认为 ...
- 2023-12-16:用go语言,给定整数数组arr,求删除任一元素后, 新数组中长度为k的子数组累加和的最大值。 来自字节。
2023-12-16:用go语言,给定整数数组arr,求删除任一元素后, 新数组中长度为k的子数组累加和的最大值. 来自字节. 答案2023-12-16: 来自左程云. 灵捷3.5 大体步骤如下: 算 ...
- python tkinter 使用(二)
python tkinter 使用(二) 本篇文章着重讲下tkinter中messagebox的使用. 1:提示框 def showinfo(event): messagebox.showinfo(& ...
- 递归产生StackOverflowError
package com.guoba.digui; public class Demo01 { public void A(){ A();//自己调用自己,递归没用好,产生错误java.lang.Sta ...
- 基于WebRTC的局域网文件传输
基于WebRTC的局域网文件传输 WebRTC(Web Real-Time Communications)是一项实时通讯技术,允许网络应用或者站点,在不借助中间媒介的情况下,建立浏览器之间点对点P2P ...
- linux文件摘选
显示/var目录下所有以1开头,以一个小写字母结尾,且中间至少出现一位数字(可以由其他字符)的文件或目录. 命令: ls -d /var/1*[0-9]*[a-z] [root@foundation0 ...
- springMVC的基本介绍与入门
1:MVC是什么? MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. Model(模型):数据模型,提高要展示的数据 现在一般是分为Value ...
- MySQL优化:12种提升SQL执行效率的有效方法
在数据库管理和优化的世界里,MySQL作为一个流行的关系型数据库管理系统,其性能优化是任何数据密集型应用成功的关键.优化MySQL数据库不仅可以显著提高SQL查询的效率,还能确保数据的稳定性和可靠性. ...
- Serverless 架构就不要服务器了?
摘要:Serverless 架构不是不要服务器了,而是依托第三方云服务平台,服务端逻辑运行在无状态的计算容器中,其业务层面的状态则被开发者使用的数据库和存储资源所记录. Serverless 是什么 ...
- 5G多输入多输出技术,到底是个啥东东?
摘要:多输入多输出技术是指在发射端和接收端分别使用多个发射天线和接收天线,使信号通过发射端与接收端的多个天线传送和接收,从而改善通信质量. 本文作者|历天一 多输入多输出技术是指在发射端和接收端分别使 ...