Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5762
Tiyi: Given the number of arrays, if h[i]>h[i-1] and h[i]>h[i+1],f (h) are added C.
H is the full arrangement of the 1-n, h[0]=0,h[n+1]=0, which requires F (h) expectations.
Because we do not know the expected value, we strongly push the case to get actually perfection arrangement F (n) of the average, we force to find the law to get the lateral values * 1/2 and the side * 1/3 can get the correct answer, after the game to see other people's solution, understand the next expectations.
Expected value: Refers to the probability of each possible result in a discrete random variable experiment multiplied by the sum of its results.
So it is easy to solve the probability of each number of results, can think of the lateral because there are two sides F = 0, the situation may have 2 kinds, can be added to f (N) has a, the probability is 1/2, there may be 6 kinds of the case, can be added to f (n), the probability is 1/3.
A special sentence n = 1.
#include <iostream> #include <stdio.h> #include <string.h> #include <
math.h> #include <algorithm> #include <queue> using namespace std;
#define INF 0x3f3f3f3f typedef long Long LL;
Const double PI = ACOs (-1.0);
const INT mod = 1e9 + 7;
const int N = 1010;
int n,m;
int a[n];
int main () {while (~SCANF ("%d", &n)} {for (int i = 0; i < n; i++) scanf ("%d", &a[i]);
if (n = = 1) {printf ("%.6lf\n", (double) a[0]);
Continue
} Double sum = 1.0/2* (a[0]+a[n-1]);
for (int i = 1; i < n-1; i++) sum + = A[I]*1.0/3;
printf ("%.6lf\n", sum);
} return 0; }