题目大意:

给你一个1*N的方格,你初始位置是在1,给你一个骰子,假设你现在的位置是X,你投掷一个骰子掷的点数是y, 那么你的新位置就是 X+y, 并且你可以得到新位置的宝藏。假如X+y > N了
那么就需要重新投掷,知道满足条件为止。输出你得到黄金的预计期望。
=========================================================================================
概率DP, 用记忆化搜索比较好。
DP[i], 代表从i点到达,第n个点所能达到的最大值。
 
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
const int INF = 1e9+;
const int MAXN = ;
int n;
double dp[MAXN], a[MAXN];
///dp[从i到达终点] = 期望 double DFS(int cur)
{
if(dp[cur] != -)
return dp[cur];
int cnt = min(n-cur, );///代表当前格子可以向向前移动多少个位置
dp[cur] = ;
for(int i=cur+; i<=cur+cnt; i++)
dp[cur] += 1.0/cnt * DFS(i);
dp[cur] += a[cur];
return dp[cur];
} int main()
{
int T, cas = ;
scanf("%d", &T);
while(T --)
{
scanf("%d", &n);
for(int i=; i<=n; i++)
{
scanf("%lf", &a[i]);
dp[i] = -;
}
dp[n] = a[n];
printf("Case %d: %.6lf\n", cas++, DFS());
} return ;
}
/* 3 3
1 2 3
*/

Light OJ 1030 - Discovering Gold的更多相关文章

  1. Light OJ 1030 - Discovering Gold(概率dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...

  2. LightOJ - 1030 Discovering Gold —— 期望

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

  3. 1030 - Discovering Gold

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

  4. Light oj 1030 概率DP

    D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768 ...

  5. [LOJ 1030] Discovering Gold

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

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

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

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

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

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

  9. light oj 1152 Hiding Gold

    题目: You are given a 2D board where in some cells there are gold. You want to fill the board with 2 x ...

随机推荐

  1. Map 迭代 两种方法

    Map 迭代 两种方法 Map<String, String> map=new HashMap<String,String>(); map.put("1", ...

  2. D2JS 的数据绑定

    D2JS 将数据绑定视为"对象-路径-渲染/收集 "组成.主要 DOM  元素和对象绑定,称为 d2js.root,非主要元素指定数据路径,通过路径定位到值,根据值可进行渲染或收集 ...

  3. PHP获取文件行数

    原文出处 提供两种实现方法,但是第一种效率最好 第一种: <?php $file_path = 'test.txt'; //文件路径 此处找一个1094644行的TXT文件 test.txt $ ...

  4. Android中全局搜索(QuickSearchBox)详解

    http://blog.csdn.net/mayingcai1987/article/details/6268732 1. 标题: 应用程序如何全面支持搜索 2. 引言: 如果想让某个应用程序支持全局 ...

  5. Android App优化建议(转载)

    假如要Google Play上做一个最失败的案例,那最好的秘诀就是界面奇慢无比.耗电.耗内存.接下来就会得到用户的消极评论,最后名声也就臭了.即使你的应用设计精良.创意无限也没用. 耗电或者内存占用等 ...

  6. TSQL Beginners Challenge 3 - Find the Factorial

    这是一个关于CTE的应用,这里我们用CTE实现阶乘 Factorial,首先来看一个简单的小实验,然后再来看题目.有的童鞋会问怎么没有2就来3了呢,惭愧,TSQL Beginners Challeng ...

  7. 在ASP中调用DLL的方法

    .net的dll已经不是严格意义上的动态连接库了,而是一个类或者类库.它是不能直接在ASP.VB等其它的应用环境中使用的.   我们可以通过COM包装器(COM callable wrapper (C ...

  8. webViewDidFinishLoad 执行多次的问题

    在做网页加载进度条的时候,发现UIWebViewDelegate中webViewDidFinishLoad方法会执行多次: - (void)webViewDidStartLoad:(UIWebView ...

  9. 解决Undefined symbols for architecture x86_64: 报错 和 ld: warning: ld: warning: ignoring file警告

    出现这种错误的情况: 用iphone5模拟器编译程序正常, 用iphone5s以上的模拟器编译出现Undefined symbols for architecture x86_64: 报错 和 ld: ...

  10. ios strong weak 的区别 与 理解

    先一句话总结:strong类保持他们拥有对象的活着,weak类他们拥有的对象被人家一牵就牵走,被人家一干就干死.(strong是一个好大哥所以strong,呵呵,weak是一个虚大哥所以weak,呵呵 ...