一排1到n的格子,每个格子上有黄金 ai ,你最开始在 1 号,每一次投骰子决定到哪一个格子,超出1~n范围则重新投掷,你到了哪个格子就得到哪个格子的金币,问最终在n 能得到金币的期望。

思路:做题经验,期望都是从后推到前,我们从最大开始dp,

1~6  种情况的传递,但是当前面的格子数少于6的时候需要特判;

 #include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<queue>
using namespace std;
const int maxn=1e3+;
int a[maxn];
double dp[maxn];
int main()
{
int T;
int cnt=;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
for(int i=n;i>=;i--){
//对格子数特判的处理
double base=n-i;
if(base>=) base=; dp[i]=a[i];
for(int j=;j<=base;j++){
dp[i]+=dp[i+j]/base;
}
}
printf("Case %d: %f\n",++cnt,dp[]);
}
return ;
}

Discovering Gold lightoj 1030的更多相关文章

  1. Discovering Gold LightOJ - 1030 (概率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 ...

  2. Discovering Gold LightOJ - 1030 || 概率与期望求法区别

    #include<cstdio>//wrong_codes #include<algorithm> using namespace std; ],anss; ],T,TT,n, ...

  3. LightOJ - 1030 Discovering Gold —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1030 1030 - Discovering Gold    PDF (English) Statistics For ...

  4. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  5. 1030 - Discovering Gold

    1030 - Discovering Gold    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 M ...

  6. [LOJ 1030] Discovering Gold

    B - Discovering Gold Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  7. 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 ...

  8. LightOj 1030 - Discovering Gold(dp+数学期望)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 题意:在一个1*n 的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得 ...

  9. LightOJ 1030 - Discovering Gold - [概率DP]

    题目链接:https://cn.vjudge.net/problem/LightOJ-1030 You are in a cave, a long cave! The cave can be repr ...

随机推荐

  1. python接口自动化-requests-toolbelt处理multipart/form-data

    1.requests-toolbelt官方文档:https://pypi.org/project/requests-toolbelt/ 2.环境安装 pip install requests-tool ...

  2. The Softmax function and its derivative

    https://eli.thegreenplace.net/2016/the-softmax-function-and-its-derivative/  Eli Bendersky's website ...

  3. python实用30个小技巧

    python实用30个小技巧 展开1.原地交换两个数字Python 提供了一个直观的在一行代码中赋值与交换(变量值)的方法,请参见下面的示例: In [1]: x,y = 10 ,20 In [2]: ...

  4. C语言 goto

    C语言 goto 功能:无条件跳转.不推荐使用 案例 #include <stdio.h> int main() { // 函数跳转.循环跳转 // 创建标志位开始 // 无条件跳转到En ...

  5. RHEL/CentOS 7中Nginx的systemd service

    源码安装的nginx ,没有systemd service 管理 nginx 下面教程,告诉你如何设置nginx 的systemd service nginx systemd的服务文件是/usr/li ...

  6. Learn from Niu

    创新的源头来自于思考,尤其是深度思考: 1. 读博过程必然会经历痛苦,思考,深度思考这么一个过程,其中思考是最重要的,尤其是深度思考. 思考之后才是创新. 2. 借用其他的知识弥补这个领域的知识,不简 ...

  7. 用C#调用外部DLL

    1.有时候需要用C#调用外部的dll,例如c++写的dll,首先需要保证dll的编译环境与本项目的环境是相同的,例如都是x86位或者x64位 2.调用声明和dll内的声明一致: function Te ...

  8. python之路递归、冒泡算法、装饰器

    map使用 完整用户名登录,注册 冒泡排序 递归 def func(arg1,arg2): if arg1 == 0: print arg1, arg2 arg3 = arg1 + arg2 prin ...

  9. 电脑进不去BIOS解决办法

    把所有外设(主要是硬盘,包括装在主板上的固态硬盘)拆下来,拆下纽扣电池给主板放电,装回纽扣电池,重启F1进入BIOS. 最终查到原因,是固态那里出的问题,固态作为启动硬盘,被自己搞得有问题了,有两个启 ...

  10. Linux - Shell - 字符串截取

    概述 简述 字符串 截取 背景 之前因为要给文件 批量重命名, 做过字符串截取 当时做好了, 也说了要写点东西 结果忘了 现在又要尝试批量 重命名 才发现之前的东西已经忘了好多 要是当时把博客写下来, ...