题目大意:

给你一个1*N的方格,你初始位置是在1,给你一个骰子,假设你现在的位置是X,你投掷一个骰子掷的点数是y, 那么你的新位置就是 X+y, 并且你可以得到新位置的宝藏。假如X+y > N了
那么就需要重新投掷,知道满足条件为止。输出你得到黄金的预计期望。
=========================================================================================
概率DP, 用记忆化搜索比较好。
DP[i], 代表从i点到达,第n个点所能达到的最大值。
 
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<queue>
  7. #include<vector>
  8. #include<map>
  9. using namespace std;
  10. typedef long long LL;
  11. const int INF = 1e9+;
  12. const int MAXN = ;
  13. int n;
  14. double dp[MAXN], a[MAXN];
  15. ///dp[从i到达终点] = 期望
  16.  
  17. double DFS(int cur)
  18. {
  19. if(dp[cur] != -)
  20. return dp[cur];
  21. int cnt = min(n-cur, );///代表当前格子可以向向前移动多少个位置
  22. dp[cur] = ;
  23. for(int i=cur+; i<=cur+cnt; i++)
  24. dp[cur] += 1.0/cnt * DFS(i);
  25. dp[cur] += a[cur];
  26. return dp[cur];
  27. }
  28.  
  29. int main()
  30. {
  31. int T, cas = ;
  32. scanf("%d", &T);
  33. while(T --)
  34. {
  35. scanf("%d", &n);
  36. for(int i=; i<=n; i++)
  37. {
  38. scanf("%lf", &a[i]);
  39. dp[i] = -;
  40. }
  41. dp[n] = a[n];
  42. printf("Case %d: %.6lf\n", cas++, DFS());
  43. }
  44.  
  45. return ;
  46. }
  47. /*
  48.  
  49. 3
  50.  
  51. 3
  52. 1 2 3
  53. */

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. Java——(六)Collection之Queue集合

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- Queue集合 Queue集合用于模拟队列这种数据结构,队列通常是指“先进先出‘(FIFO)的容 ...

  2. iOS UIKit:viewController之动画(5)

    当弹出一个view controller时,UIKit提供了一些标准转换动画,并且也支持用户自定义的动画效果. 1 UIView动画 UIView是自带动画实现功能,其中有两种方式实现:        ...

  3. transition的四个属性

    transition-property 规定设置过渡效果的 CSS 属性的名称. transition-duration 规定完成过渡效果需要多少秒或毫秒. transition-timing-fun ...

  4. (九)打印机驱动设置—USB接口的设置

    佳博打印机代理商淘宝店https://shop107172033.taobao.com/index.htm?spm=2013.1.w5002-9520741823.2.Sqz8Pf 在此店购买的打印机 ...

  5. JavaScript HTML DOM

    JavaScript HTML DOM 通过 HTML DOM,可访问 JavaScript HTML 文档的所有元素. HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象 ...

  6. [转]Delphi I/O Errors

    The following are the Windows API (and former DOS) IO errors, which are also the IO errors often ret ...

  7. 安装freebsd9 出现 mountroot>怎么办

    之前手欠把linux分区给删了想重装freebsd 重新进入的时候mbr提示grub信息 用PE把MBR删掉 之后再用freebsd光盘启动出现mountroot> 就用mountroot> ...

  8. css学习--inline-block详解及dispaly:inline inline-block block 三者区别精要概括

    *知识储备: 内联元素:是不可以控制宽和高.margin等:并且在同一行显示,不换行. 块级元素:是可以控制宽和高.margin等,并且会换行. 1.inline-block 详解 (1)一句话就是在 ...

  9. 干掉Google字体,WordPress速度暴涨

    2014年7月7日23:40:31 因为Google被墙,WordPress引用的Google字体总会加载很长时间,严重影响打开速度. 安装WordPress插件 Disable Google Fon ...

  10. [前端笔记]第三篇:JavaScript

    JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. 一.代码存放位置 J ...