一排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. vjudge I - Vladik and fractions 一道小学生的提。

    原题链接:https://vjudge.net/contest/331993#problem/I Vladik and Chloe decided to determine who of them i ...

  2. BZOJ的思维题

    5085:最大 给你一个n×m的矩形,要你找一个子矩形,价值为左上角左下角右上角右下角这四个数的最小值,要你最大化矩形 的价值. 关键点是要想到把这些值排序 值从小到大考虑,比如说现在最小的值是(x1 ...

  3. IntelliJ WebStorm 2020最新 永久破解激活教程【全网最强,可用至2100年】

    说明:都到了2020年,当然要用最新的IDE,目前最新是2019.3.1版本 ①IntelliJ WebStorm 2019.3.1安装永久破解[最强] 一. 在官网下载WebStorm安装包  链接 ...

  4. JS变量和数据类型及其转化

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 关于XXE

    NJUPT CTF2019: 做题的时候,抓包看了一下,响应XML格式消息,并没有严格过滤,这道题读文件, <!DOCTYPE foo [ <!ENTITY xxe SYSTEM &quo ...

  6. Pycharm操作数据库

    Pymysql 用于连接mysql数据库 连接数据库 data_ip = "192.168.34.128" data_name = "lch" data_pwd ...

  7. Docker的安装和操作(虚拟机+linux系统)

    1.简介 Docker是一个开源的应用容器引擎:是一个轻量级容器技术: Docker支持将软件编译成一个镜像:然后在镜像中各种软件做好配置,将镜像发布出去,其他使用者可以直接使用这个镜像: 运行中的这 ...

  8. JUC-ThreadPool线程池

    一.为什么用线程池 例子:10年前单核CPU电脑,假的多线程,像马戏团小丑玩多个球,CPU需要来回切换. 现在是多核电脑,多个线程各自跑在独立的CPU上,不用切换效率高. 线程池的优势: 线程池做的工 ...

  9. springboot静态资源

    https://blog.csdn.net/yali_aini/article/details/83213695 https://blog.csdn.net/sihai12345/article/de ...

  10. R语言函数话学习笔记5

    使用Tidyverse完成函数化编程 (参考了家翔学长的笔记) 1.magrittr包的使用 里面有很多的管道函数,,可以减少代码开发时间,提高代码可读性和维护性 1.1 四种pipeline 1.1 ...