题目大意:

给你一个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. Oracle中wm_concat()的使用方法

    以下两种方式使用wm_concat()的使用方法是等效的. 方法一:使用窗口函数,wm_concat支持窗口函数 select distinct classKey,className, classOr ...

  2. HDU 5592 ZYB's Premutation(树状数组+二分)

    题意:给一个排列的每个前缀区间的逆序对数,让还原 原序列. 思路:考虑逆序对的意思,对于k = f[i] - f[i -1],就表示在第i个位置前面有k个比当前位置大的数,那么也就是:除了i后面的数字 ...

  3. ASP.NET Boilerplate 工作单元

    从上往下说起,框架使用castle拦截器,拦截实现了IApplication.IRepository接口的所有方法,和使用了UnitOfWork 特性的方法,代码如下 internal class U ...

  4. Android -- 双击退出

    实现android双击后退键退出当前APP功能 实现该功能基本思路是, 1, 监听后退键 , 比较两次后退间隔 , 低于两秒则出发退出 2, 退出当前APP 我选择在基类中BaseActivity 中 ...

  5. linq学习笔记:将List<T> 转换为 Dictionary<T Key,T Value>

    运用Linq,将List<T> 转换为 Dictionary<T Key,T Value> 即:List<T>  ToDictionary<T Key,T V ...

  6. XFire中Services.xml 配置的一些细节

    昨天第一次调XFire引擎,放在Tomcat里之后老是报错,检查了很久没有发现什么问题,一直很费解. 后来在网上看到一篇文章<XFire services.xml 配置文件补充说明>,根绝 ...

  7. MySQL 5.6 解决InnoDB: Error: Table "mysql"."innodb_table_stats" not found.问题

    在安装MySQL 5.6.30时,安装完成后,后台日志报如下警告信息:2016-05-27 12:25:27 7fabf86f7700 InnoDB: Error: Table "mysql ...

  8. iOS 从网络获取son并解析

    NSString* GXURL = PURL; GXURL = [GXURL stringByAppendingString:@"/index.php/Api/android_getRank ...

  9. Linux sz rz

    借助XShell,使用linux命令 root 账号登陆: su root 1.编译安装 wget http://www.ohse.de/uwe/releases/lrzsz-0.12.20.tar. ...

  10. php中的JSON中文处理

    最近在PHP中要输出JSON,上网查了一下,对中文支持不太好,要不就先转成utf-8的编码,再用json_encode生成,客户端还要再utf-8转中文.对于网页已经用GB2312的服务器,不想这样折 ...