数学概念——D 期望
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-6will 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
解题思路:
这题要倒着推,由N推向1
设d[k]为到达k这个位置时得到金币的期望,m为该点和N这个位置的距离,a[k]为k这个位置的金币数,因为走的位置不能超过N,所以要取min(m,6)
那么d[k] = 1 / min(m,6) * (d[k + 1] + dp[k+2] + … + d[min(m,6)]) + a[k]
程序代码:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,a[];
double d[];
void init()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
}
void work()
{
memset(d,,sizeof(d));
d[n]=a[n];
for(int i=n-;i>=;i--)
{
d[i]=a[i];
int k=min(,n-i);
for(int j=;j<=k;j++)
d[i]+=d[i+j]*(1.0/k);
} }
int main()
{
int t,Case=;
scanf("%d",&t);
while(t--)
{
init();
work();
printf("Case %d: %.10lf\n",++Case,d[]);
}
return ;
}
数学概念——D 期望的更多相关文章
- 数学概念——E 期望(经典问题)
E - 期望(经典问题) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- 21副GIF动图让你了解各种数学概念
baidu 21副GIF动图让你了解各种数学概念
- 转:21副GIF动图让你了解各种数学概念
21副GIF动图让你了解各种数学概念
- Math concepts / 数学概念
链接网址:Math concepts / 数学概念 – https://www.codelast.com/math-concepts-%e6%95%b0%e5%ad%a6%e6%a6%82%e5%bf ...
- slot游戏中的数学概念
最近研究slot 算法,看了大量的英文资料,因为母语中文,一直使用中文的英文小白来说,好心塞,悔不当初没学好英文. 下文是从众多的英文中摘录的唯一能够看明白的概念.先给自己留着,到时候深入研究可以看 ...
- 数学概念 z
数学是很难的科学,但因为它是科学家用数学来解释宇宙的语言,我们无可避免的要学习它.看看下面的这些 GIF 动图,它们提供了视觉的方式来帮助你理解各种数学技巧. 1.椭圆的画法 2.杨辉三角问题(Pas ...
- 数学概念——F 概率(经典问题)birthday paradox
F - 概率(经典问题) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- 21副GIF动图让你了解各种数学概念(转。太强大了)
“让我们面对它:总的来说数学是不容易的,但当你征服了问题,并达到新的理解高度,这就是它给你的回报.” ——Danica McKellar 数学是很难的科学,但因为它是科学家用数学来解释宇宙的语言,我们 ...
- 数学&动态规划:期望DP
BZOJ3036 给定一张有向无环图,起点为1,终点为N,每个点i有ki条出边,从每个点走其中一条出边的概率是1/ki,求从1到N的期望步数 我们注意到一点,走每条边都是等概率的,那么就相当于 给定一 ...
随机推荐
- HTML5 WebAudioAPI简介(一)
一.常用对象 1.AudioContext对象 AudioContext是一个专门用于音频处理的接口,并且原理是讲AudioContext创建出来的各种节点(AudioNode)相互连接,音频数据流经 ...
- appium系列教程(转载)
1.系列文章:转载来源:乙醇的cnblog http://www.kuqin.com/shuoit/20140704/340994.html 2.环境部署:http://www.51testing.c ...
- node 搭建开发框架express
参考地址: http://www.itnose.net/detail/6095003.html 开发环境 E:\project> node -v v0.10.30 E:\project> ...
- SQL Server中的死锁
简介 死锁的本质是一种僵持状态,是多个主体对于资源的争用而导致的.理解死锁首先需要对死锁所涉及的相关观念有一个理解. 一些基础知识 要理解SQL Server中的死锁,更好的方式是通过类比从更大的面理 ...
- 【转】 CoreGraphics QuartzCore CGContextTranslateCTM 用法
原文:http://blog.csdn.net/sqc3375177/article/details/25708447 CoreGraphics.h 一些常用旋转常量 #define M_E 2.71 ...
- OC - 23.核心动画基础
概述 简介 核心动画提供了一组非常强大的动画API,通过该组API可以高效的实现绝大部分绚丽的动画效果 注意事项 核心动画的操作在子线程中执行,不会阻塞主线程 核心动画直接作用与CALayer对象上, ...
- Java线程(学习整理)--4---一个简单的生产者、消费者模型
1.简单的小例子: 下面这个例子主要观察的是: 一个对象的wait()和notify()使用情况! 当一个对象调用了wait(),那么当前掌握该对象锁标记的线程,就会让出CPU的使用权,转而进入该对 ...
- Git 基础再学习之:git checkout -- file
首先明白一下基本概念和用法,这段话是从前在看廖雪峰的git教程的时候摘到OneNote的 准备工作: 新建了一个learngit文件夹,在bash中cd进入文件夹,用以下命令创建一个仓库. $ git ...
- 页面点击关闭弹出提示js代码
代码效果为: <script> window.onbeforeunload = function() { return "您好!\n我是abc\n —————————————— ...
- 【Linux】vi编辑器命令
1)进入vi的命令 vi filename : 打开或新建文件,并将光标置于第一行首 vi +n filename : 打开文件,并将光标置于第n行首 ...