创想实验室
我们都是梦想家

Permutation Bo

描述

There are two sequences h1hnh1∼hn and c1cnc1∼cn. h1hnh1∼hn is a permutation of 1n1∼n. particularly, h0=hn+1=0h0=hn+1=0.

We define the expression [condition] is 1 when conditioncondition is True,is 0 when conditioncondition is False.

Define the function f(h)=ni=1ci[hi>hi1  and  hi>hi+1]

Bo have gotten the value of c1cn, and he wants to know the expected value of f(h).

输入

This problem has multi test cases(no more than 12).

For each test case, the first line contains a non-negative integer n(1n1000), second line contains nn non-negative integer ci(0ci1000).

输出

For each test cases print a decimal – the expectation of f(h).

If the absolute error between your answer and the standard answer is no more than 104, your solution will be accepted.

样例输入

4
3 2 4 5
5
3 5 99 32 12

样例输出

6.000000
52.833333

代码

 

网站所发布的代码已提交通过,代码可能经过修改防止抄袭,未经允许不得转载:创想实验室 » Permutation Bo
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址