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< ...
随机推荐
- [ABC310G] Takahashi And Pass-The-Ball Game
Problem Statement There are $N$ Takahashi. The $i$-th Takahashi has an integer $A_i$ and $B_i$ balls ...
- linux环境下脚本部署项目出现nohup: redirecting stderr to stdout问题
解决办法: 把后面的 "&" 改成 "2>&1 &" 最终改为: nohup java -jar ${JAR_NAME} --lo ...
- 使用Mybatis自定义插件实现不侵入业务的公共参数自动追加
背景 后台业务开发的过程中,往往会遇到这种场景:需要记录每条记录产生时间.修改时间.修改人及添加人,在查询时查询出来. 以往的做法通常是手动在每个业务逻辑里耦合上这么一块代码,也有更优雅一点的做法是写 ...
- 春秋云镜 - CVE-2022-28512
Fantastic Blog (CMS)是一个绝对出色的博客/文章网络内容管理系统.它使您可以轻松地管理您的网站或博客,它为您提供了广泛的功能来定制您的博客以满足您的需求.它具有强大的功能,您无需接触 ...
- 【OpenCV】在MacOS上源码编译OpenCV
前言 在做视觉任务时,我们经常会用到开源视觉库OpenCV,OpenCV是一个基于Apache2.0许可(开源)发行的跨平台计算机视觉和机器学习软件库,它具有C++,Python,Java和MATLA ...
- 云MSP服务案例丨某知名制造集团的Oracle RAC部署实践
简介: 随着DT时代到来,移动互联网.物联网开始高速发展,更多的企业意识到了数据库架构选型对业务发展的重要性,如何管理和利用好数据已经变得越来越重要.Oracle作为世界上目前最流行的关系型数据库管理 ...
- Mybatis源码4 Cache的实现和其原理
Mybatis CachingExecutor, 二级缓存,缓存的实现 一丶二级缓存概述 上一章节,我们知道mybaits在构造SqlSession的时候,需要让SqlSession持有一个执行器,如 ...
- 使用鼠标在图片上拖拽矩形框vue
<template> <div> <img class="no-drag" src="https://dashanbook.oss-cn-s ...
- Flink实时处理入门
Flink实时处理入门 1.Flink框架介绍 Flink 诞生于欧洲的一个大数据研究项目 StratoSphere.它是由 3 所地处柏林的大学和欧洲其他一 些大学在 2010~2014 年共同进行 ...
- 常见的6种MySQL约束
摘要:一篇文章带你彻底了解MySQL各种约束 MySQL约束 <1> 概念 是一种限制,它是对表的行和列的数据做出约束,确保表中数据的完整性和唯一性. <2> 使用场景 创建表 ...