(LightOJ 1030)期望dp
You are in a cave, a long cave! The cave can be represented by a x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position . Now each turn you throw a perfect sided dice. If you get X in the dice after throwing, you add X to your position and collect all the gold from the new position. If your new position is outside the cave, then you keep throwing again until you get a suitable result. When you reach the Nth position you stop your journey. Now you are given the information about the cave, you have to find out the expected number of gold you can collect using the given procedure. Input
Input starts with an integer T (≤ ), denoting the number of test cases. Each case contains a blank line and an integer N ( ≤ N ≤ ) denoting the dimension of the cave. The next line contains N space separated integers. The ith integer of this line denotes the amount of gold you will get if you come to the ith cell. You may safely assume that all the given integers will be non-negative and no integer will be greater than . Output
For each case, print the case number and the expected number of gold you will collect. Errors less than - will be ignored. Sample Input
Output for Sample Input Case : 101.0000000000
Case : 13.000
Case :
题意:
方法:
#include<cstdio>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a));
const int oo = 0x3f3f3f3f;
const int N = ;
double dp[N];
int a[N];
int main()
{
int t,n,con=;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
met(dp,);
dp[]=;
for(int i=;i<=n;i++)
{
int k=max(i-,);
for(int j=k;j<i;j++)
{
double y=(j>=n-?(n-j):);
dp[i]+=dp[j]/y;
}
}
double sum=;
for(int i=;i<=n;i++)
sum+=dp[i]*a[i];
printf("Case %d: %.10f\n",con++,sum);
}
return ;
}
(LightOJ 1030)期望dp的更多相关文章
- LightOJ - 1030 期望+dp
题目链接:https://vjudge.net/problem/25907/origin 一个山洞,里面有有1到n个位置,每个位置都有一定的金币,你有一个六面的骰子,一开始你在1,每次摇到了哪个数就往 ...
- lightoj 1030 概率dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1030 #include<cstdio> #include<cstri ...
- lightOJ 1030(期望)
题意:有一个迷宫是1×n的格子,一个人每到一个格子就能够把这个格子内的金子所有拿走,刚開始站在第1个格子,然后開始掷骰子得到点数x,他就要从当前位置走到加x的位置.假设发现位置是大于n的就又一次掷骰子 ...
- LightOJ 1030 Discovering Gold (概率/期望DP)
题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...
- LightOj:1030-Discovering Gold(期望dp模板)
传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...
- LightOJ 1248 Dice (III) (期望DP / 几何分布)
题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...
- 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 ...
- Light oj 1030 概率DP
D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768 ...
- 概率dp+期望dp 题目列表(一)
表示对概率和期望还不是很清楚定义. 目前暂时只知道概率正推,期望逆推,然后概率*某个数值=期望. 为什么期望是逆推的,例如你求到某一个点的概率我们可以求得,然后我们只要运用dp从1~n每次都加下去就好 ...
- LightOJ 1364 树形DP
52张扑克牌,问拿到指定数量的4个花色的最少次数期望是多少,其中拿到joker必须马上将其视作一种花色,且要使后续期望最小. 转移很容易想到,主要是两张joker的处理,一个状态除了普通的4个方向的转 ...
随机推荐
- E297: Write error in swap file解决方法
vi打开配置文件后显示E297: Write error in swap file,检查磁盘发现磁盘满了.使用du –max-depth=1 | sort –n –r 查找大文件所在位置并删除.
- Nexus5如何手动OTA更新系统到4.4.3、4.4.4及常见问题回答
这里将记录一套行之有效的Nexus5手动升级方法,以帮助看见这篇文章的朋友成功将手头的Nexus5升级到4.4.4. 因为谷歌服务器的事,我的这次OTA更新起来走了很多弯路.我试过挂VPN等待系统来更 ...
- 易元平台使用-MVC体会
M:服务-提供数据 V:freemaker-提供显示方式 C:控制器-控制显示方式
- iOS从生成证书到打包上架-01(详细2016-10最新)
今天项目上架成功,在此小结一下这个过程,希望对这个流程有疑惑的小伙伴少走弯路(大神请忽略此文) 关于证书是什么,请自行百度,Google,这里直接上流程. 1.首先打开苹果开发者网站,Apple De ...
- chrome浏览器当表单自动填充时,怎么去除浏览器自动添加的默认样式。
参考blog来自 http://segmentfault.com/q/1010000000671971 chrome浏览器当表单自动填充时,怎么去除浏览器自动添加的默认样式. 一.发现该问题的原因-是 ...
- 【剪枝】HDU 1010——tempter of the bone
来源:点击打开链接 看上去数据规模很小,但是必须要剪枝,否则直接爆TLE. 通过这个题可以练习奇偶剪枝. 另外:还有一个优化方式,如果所有步数走完了门还没关,则直接返回结果"NO" ...
- html传參中?和&
<a href="MealServlet?type=findbyid&mid=<%=m1.getMealId()%> 在这句传參中?之后的代表要传递的參数当中有两个 ...
- linux-多线程
一.什么是线程? 线程是进程的一个实体,是CPU调度和分派的基本单位,它是比进程更小的能独立执行的基本单位.线程自己基本上不拥有系统资源,仅仅拥有一点在执行中不可缺少的资源(如程序计数器,一组寄存器和 ...
- 【十分钟教会你汇编】MIPS编程入门(妈妈说标题要高大上,才会有人看>_<!)
无意中找到一篇十分好用,而且篇幅也不是很大的入门教程,通篇阅后,再把“栗子”敲一遍,基本可以有一个比较理性的认识,从而方便更好地进一步深入学习. 废话不多说,上干货(英语好的直接跳过本人的渣翻译了哈— ...
- 初识jsp
复习: 1.servlet生命周期: (1)默认是以第一次请求的时候创建并初始化Servlet,而且只做一次.(构造函数 init()) web.xml(配置后,是可以达到在服务启动后,立刻进行ser ...