LightOJ 1030 Discovering Gold

期望,$dp$。

设$ans[i]$为$i$为起点,到终点$n$获得的期望金币值。$ans[i]=(ans[i+1]+ans[i+2]+ans[i+3]+ans[i+4]+ans[i+5]+ans[i+6])/6+a[i]$,不到$6$个的单独处理一下。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c = getchar();
    x = 0;
    while(!isdigit(c)) c = getchar();
    while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
}

int a[120],T,n;
double ans[120];

int main()
{
    scanf("%d",&T); int cas=1;
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            ans[i]=1.0*a[i];
        }
        for(int i=n-1;i>=1;i--)
        {
            int cnt=0; double sum=0;
            for(int j=1;j<=6;j++)
            {
                if(i+j>n) break;
                cnt++; sum=sum+ans[i+j];
            }
            ans[i]=ans[i]+sum/cnt;
        }
        printf("Case %d: %lf\n",cas++,ans[1]);
    }
    return 0;
}

 

posted @ 2017-01-16 14:08  Fighting_Heart  阅读(155)  评论(0编辑  收藏  举报