#P10953. [2015杭电多校]MZL's munhaff function
[2015杭电多校]MZL's munhaff function
MZL's munhaff function
Problem Description
MZL is a mysterious mathematician, and he proposed a mysterious function at his young age. Stilwell is very confused about this function, and he need your help. First of all, given positive integers and . Then, generate positive integers
Define for
$$f(i,j)=\left\{\begin{matrix} 0 & & (i,j)=(1,1)\\ min(f(i-1,j+1),f(i,\lceil\frac{j}{2}\rceil)+B_i) & & i,j\in[1,n],~(i,j)\neq(1,1) \\ 10^{11037} & & otherwise \end{matrix}\right. $$Find .
Input
The first line of the input contains a single number , the number of test cases. For each test case, the first line contains a positive integer , and the next line contains positive integers . , , , .
Output
For each test case, output in a line.
Sample Input
3
3
1 1 1
5
28 26 25 24 1
10
996 901 413 331 259 241 226 209 139 49
Sample Output
5
233
11037
Hint
case 1 : f(1,1)=0 f(1,2)=f(1,1)+3=3 f(1,3)=f(1,2)+3=6 f(2,1)=min(f(2,1)+2,f(1,2))=3 f(2,2)=min(f(2,1)+2,f(1,3))=5 f(2,3)=f(2,2)+2=7 f(3,1)=min(f(3,1)+1,f(2,2))=5
Author
SXYZ
Source
2015 Multi-University Training Contest 5