LightOJ 1030-Discovering Gold

原创 2015年11月20日 23:04:47

题意:

题意就是说给你一个长度为n的序列,初始在1位置,每次可以掷骰子,1-6,如果没有越界,就可以往前走,并且得到目标格子的值。走到最后一个格子结束。问最后获得分数的期望。
一般来说期望都是倒着推。
设dp[i]表示从i号格子出去的期望,那么dp[i]+=dp[i+step]*1.0/(6,n-i).

代码:

//
//  Created by  CQU_CST_WuErli
//  Copyright (c) 2015 CQU_CST_WuErli. All rights reserved.
//
// #include<bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#define CLR(x) memset(x,0,sizeof(x))
#define OFF(x) memset(x,-1,sizeof(x))
#define MEM(x,a) memset((x),(a),sizeof(x))
#define ALL(x) x.begin(),x.end()
#define AT(i,v) for (auto &i:v)
#define For_UVa if (kase!=1) cout << endl
#define BUG cout << "I am here" << endl
#define lookln(x) cout << #x << "=" << x << endl
#define look(x) cout << #x << "=" << x
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
#define Root 1,n,1
#define BigInteger bign
template <typename T> T max(T& a,T& b) {return a>b?a:b;}
template <typename T> T min(T& a,T& b) {return a<b?a:b;}
int gcd(int a,int b) {return b==0?a:gcd(b,a%b);}
long long gcd (long long a,long long b) {return b==0LL?a:gcd(b,a%b);}
const int MAX_L=2005;// For BigInteger
const int INF_INT=0x3f3f3f3f;
const long long INF_LL=0x7fffffff;
const int MOD=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
typedef long long  ll;
using namespace std;

const int N=110;

int n;
double w[N];
double dp[N];

int main(){
#ifdef LOCAL
    freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);
//  freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);
#endif
    int T_T;
    for (int kase=scanf("%d",&T_T);kase<=T_T;kase++) {
        printf("Case %d: ",kase);
        cin >> n;
        for (int i=1;i<=n;i++) cin >> w[i];
        CLR(dp);
        dp[n]=w[n];
        for (int i=n-1;i>=1;i--) {
            int step=min(6,n-i);
            dp[i]+=w[i];
            for (int j=1;j<=step;j++) {
                dp[i]+=1.0/step*dp[i+j]; 
            }
        }
        printf("%.6lf\n",dp[1]);    
    }
    return 0;
}
版权声明:欢迎转载,转载请注明出处http://blog.csdn.net/cquwel

LightOJ1030---Discovering Gold(概率dp)

You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave c...

LightOJ 1030 Discovering Gold + Hdu4405 Aeroplane chess (期望)

相似的两题一起总结。 LightOJ 1030 Discovering Gold 题目链接:http://lightoj.com/volume_showproblem.php?problem=...

lightoj 1030 Discovering Gold

1030 - Discovering Gold     PDF (English) Statistics Forum Time Limit: ...

【期望dp】LightOJ 1030 Discovering Gold

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84305#problem/B 期望dp,跟之前一篇文章飞行棋的很像,注意i+j>N情...

lightoj 1030 Discovering Gold (基础概率dp)

lightoj 1030 Discovering Gold (基础概率dp)

lightoj1030 - Discovering Gold【概率dp求期望】

1030 - Discovering Gold     PDF (English) Statistics Forum Time Limit: ...

lightoj 1030 Discovering Gold 概率dp

题目: You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of...
  • Na_OH
  • Na_OH
  • 2017年04月19日 01:09
  • 141

1030 - Discovering Gold (lightoj 1030 概率DP)

1030 - Discovering Gold PDF (English) Statistics Forum Time L...

Light OJ 1030 - Discovering Gold(期望)

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

B - Discovering Gold Light oj 1030

You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave c...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LightOJ 1030-Discovering Gold
举报原因:
原因补充:

(最多只允许输入30个字)