-
Notifications
You must be signed in to change notification settings - Fork 0
/
loj1030.cpp
55 lines (40 loc) · 822 Bytes
/
loj1030.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*using namespace std;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>*/
#include<stdio.h>
#include<string.h>
#define min(a,b) ((a<b)?(a):(b))
int cost[105],N;
double dp[105];
bool cheaque[105];
double solve(int pos)
{
if(pos==N)
return cost[pos];
if(cheaque[pos]==true)
return dp[pos];
int cnt = min(6,N-pos);
double r=0.0;
for(int i=1;i<=cnt;i++)
{
r+=((double)(cost[pos]+solve(pos+i))/cnt);
}
cheaque[pos]=true;
return dp[pos]=r;
}
int main()
{
int T,n,i,Case=1;
scanf("%d",&T);
while(T--)
{
memset(cheaque,false,sizeof(cheaque));
scanf("%d",&N);
for(i=1;i<=N;i++)
scanf("%d",&cost[i]);
printf("Case %d: %.10lf\n",Case++,(double)solve(1));
}
return 0;
}