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

建议使用的浏览器:

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

5492:Find a path

题目描述
Frog fell into a maze. This maze is a rectangle containing $N$ rows and $M$ columns. Each grid in this maze contains a number, which is called the magic value. Frog now stays at grid (1, 1), and he wants to go to grid (N, M). For each step, he can go to either the grid right to his current location or the grid below his location. Formally, he can move from grid (x, y) to (x + 1, y) or (x, y +1), if the grid he wants to go exists.
Frog is a perfectionist, so he'd like to find the most beautiful path. He defines the beauty of a path in the following way. Let’s denote the magic values along a path from (1, 1) to (n, m) as $A_1, A_2, … A_{N+M-1}$, and $A_{avg}$ is the average value of all $A_i$. The beauty of the path is $(N + M – 1)$ multiplies the variance of the values:$(N+M-1)\sum_{i=1}^{N+M-1}(A_{i}-A_{avg})^{2}$
In Frog's opinion, the smaller, the better. A path with smaller beauty value is more beautiful. He asks you to help him find the most beautiful path.
输入解释
The first line of input contains a number $T$ indicating the number of test cases ($T≤50$).
Each test case starts with a line containing two integers $N$ and $M$ ($1≤N,M≤30$). Each of the next $N$ lines contains $M$ non-negative integers, indicating the magic values. The magic values are no greater than 30.
输出解释
For each test case, output a single line consisting of “Case #X: Y”. $X$ is the test case number starting from 1. $Y$ is the minimum beauty value.
输入样例
1
2 2
1 2
3 4
输出样例
Case #1: 14
来自杭电HDUOJ的附加信息
Recommend wange2014

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

源链接: HDU-5492

最后修改于 2020-10-25T23:23:08+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)