一排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. @RendSection{"scripts",require:false}的作用

    MVC视图中,Javascripts代码被放于下面的Razor代码中(@section Scripts{}). 好处:在视图进行JavaScript编程时,是一个很好的实践,在共享视图(_Layout ...

  2. Wannafly Camp 2020 Day 6M 自闭 - 模拟

    按题意模拟,又乱又烦,没什么可说的 #include <bits/stdc++.h> using namespace std; #define int long long int n,m, ...

  3. SCSS的基本操作

    Sass是成熟.稳定.强大的CSS预处理器,而SCSS是Sass3版本当中引入的新语法特性,完全兼容CSS3的同时继承了Sass强大的动态功能. 特性概览 CSS书写代码规模较大的Web应用时,容易造 ...

  4. android 获取所有SD卡目录

    //返回sd卡路径public static List<String> getStorageDirectories(Context context) { StorageManager sm ...

  5. python中可变类型和不可变类型数据的复制

    常见的复制方式有以下5种第1种:通过等号[=]复制 - 不论可变还是不可变数据类型,通过[=]复制后都指向同一个内存地址: - 改变复制后的数据(例子中的anotherStr,anotherList) ...

  6. 3ds Max File Format (Part 3: The department of redundancy department; Config)

    Now we'll have a look at the Config stream. It begins like follows, and goes on forever with various ...

  7. AdaBoost级联分类器

    Haar分类器使用AdaBoost算法,但是把它组织为筛选式的级联分类器,每个节点是多个树构成的分类器,且每个节点的正确识别率很高.在任一级计算中,一旦获得“不在类别中”的结论,则计算终止.只有通过分 ...

  8. range()用法

    来源:http://www.cnblogs.com/wangwp/p/4535299.html 例子:http://www.cnblogs.com/hongten/p/hongten_python_r ...

  9. ASP.NET Razor简介

    Razor 不是一种编程语言.它是服务器端的标记语言. 什么是 Razor? Razor 是一种标记语法,可以让您将基于服务器的代码(Visual Basic 和 C#)嵌入到网页中. 基于服务器的代 ...

  10. c#中的yield词法

    yield关键字的作用是将当前集合中的元素立即返回,实例: 通过断点可以看到,控制台每显示一个集合中的元素,都会到query方法中去取集合元素. 其实yield return是“语法糖”,其本质是生成 ...