[水+期望dp] light oj 1030 Discovering Gold

题意:

给n个点,每个点都有一个财宝。

你从1这个点开始出发,假设你在i这个点,每次随机走1~min(6,n-i)步。

每到达一个点就拿走财宝。

问最后拿到财宝的期望。

思路:

水的题目。

dp[n]=v[n]

然后逐个往前推。

就是注意一下步数是 1~min(6,n-i)

代码:

#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
#include"map"
#include"stack"
#include"vector"
#define ll __int64
#define inf -999999999999999999LL
using namespace std;
int main()
{
    int t,cas=1;
    cin>>t;
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int v[123];
        double dp[123];
        for(int i=1;i<=n;i++) scanf("%d",&v[i]);
        memset(dp,0,sizeof(dp));
        dp[n]=v[n];
        for(int i=n-1;i>=1;i--)
        {
            int cnt=min(6,n-i);
            dp[i]=v[i];
            for(int j=1;j<=cnt;j++)
            {
                dp[i]+=1.0/cnt*dp[i+j];
            }
        }
        printf("Case %d: %.7f\n",cas++,dp[1]);
    }
    return 0;
}
时间: 2024-07-29 03:14:16

[水+期望dp] light oj 1030 Discovering Gold的相关文章

Light OJ 1030 - Discovering Gold(期望)

1030 - Discovering Gold PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in

Light OJ 1030 - Discovering Gold(概率dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的地方, 每个格子中都有价值为v[i]的宝藏. 有一个6面的骰子,数字为从1-6, 每次摇一次骰子, 得到的数字x后, 你可以到达距离当前位置大x的位置, 并且得到那个位置的宝藏. 如果要走的位置在n的外面, 那么在此摇骰子, 直到找到一个合适的数字.到达n位置的时候结束. 现在想知道走到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 \times N\) grid. Each cell of the cave can contain any amount of gold. Initially you are in position \(1\). Now each turn you throw a perfect \(6\) s

Light oj 1030 概率DP

D - Discovering Gold Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1030 Description You are in a cave, a long cave! The cave can be represented by a 1

lightoj 1030 Discovering Gold[ 期望 ]

B - Discovering Gold Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If yo

[DP] Light Oj 1017 Brush(III)

题目为 light oj 1017. 现在是凌晨两点二十分,我却毫无睡意,这题折腾了我一个晚上,一直没有做对,最后发现转移方程忽略了一个重要的条件,泪奔-. 干脆不睡觉,写一篇题解警醒自己,也算是对于自己考虑问题智障的惩罚. 我真是个智障 0 s 0 ..... 题目大意是 , 给你N个二维坐标上的点 (x,y) , 每一个点代表一个污渍,现在有一把宽度为 W 的刷子,平行于 x 轴移动 K 次,问,最多能擦掉多少污渍. 很明显这题和x坐标一点关系都没有(因为刷子沿着平行x轴移动,并可以移动无限

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 of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice a

LightOJ 1030 Discovering Gold (期望)

https://vjudge.net/problem/LightOJ-1030 题意: 在一个1×N的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得到该格子的金币. 现在从1格子开始,每次摇骰子,他就前进几步,但有一种情况例外,如果当前位置+色子数 > N,那么他就会重新摇色子. 走到N这个位置的话,意味着游戏结束了. 问游戏结束时,这个人得到金币的期望. 思路:这里给出两种做法,一种是正序求解,一种是逆序求解. ①正序求解: 这种做法是从前往后计算每个格子的概率,假设我们现在处于第

LightOJ 1030 Discovering Gold(期望 概率)

正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / min(n - j, 6) 又到达i时有价值val[i],到达i的概率为p[i],故exp[i] += val[i] * p[i] #include<cstdio> #include<iostream> #include<cstdlib> #include<cstr