当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7226:Darnassus

题目描述
$\space \space$*Even the World Tree must bow to the cycle of life. Everything born will die.*

$\space \space$*Archimonde has hurt it once, Sylvanas burnt it again.*

$\space \space$*Now the World Tree is slowly recovering.*

The World Tree is burnt apart into $n$ parts. Now it tries to rebuild itself.

Each part of the World Tree has an attribute $p_i$, and all $p_i\ (1\leq i\leq n)$ forms a permutation of $1,2,3...n$.

For all $1 \leq i < j \leq n$, if the World Tree wants to grow an edge connecting part $i$ and part $j$ directly, it needs to spend $|i-j| * |p_i-p_j|$ energy. $|x|$ means the absolute value of $x$.

The World Tree is very smart, so it will grow some edges such that all its $n$ parts become connected (in other words, you can go from any part to any other part using only the edges that have been grown), spending the minimum energy.

Please calculate the minimum energy the World Tree needs to spend.
输入解释
The input consists of multiple test cases.

The first line contains an integer $T\ (1\leq T \leq 5)$ denoting the number of test cases.

For each test case, the first line contains a single integer $n(1 \leq n \leq 50000)$.

The second line contains $n$ integers $p_i\ (1 \leq p_i \leq n)$, it's guaranteed that all $p_i$ forms a permutation.
输出解释
For each test case, output one line containing one integer indicating the answer.
输入样例
2
5
4 3 5 1 2
10
4 7 3 8 6 1 9 10 5 2
输出样例
7
24

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7226

最后修改于 2022-09-15T06:17:30+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 524288/524288K(Java/Others)