algorithm - 找到矩阵运算的有效算法

标签 algorithm

这是一道面试题:

For a matrix, we define an operation that when we add 1 to one entry, all the surrounding entries (up, down, left, right) will also added by 1. Given a positive matrix, find an algorithm to determine if the matrix can be constructed from zero matrix using such operation.

解决问题的有效算法是什么?

我目前能想到的就是用回溯的方式尝试每一种可能的组合,但是这样效率肯定不高。这个问题有点像 Lights Off 游戏,但这里不是 0/1,这会变得更复杂。

谢谢。

编辑:

例如:

3 3 can be constructed from 0 0 -> 1 1 -> 2 2 -> 3 3
1 2                         0 0    1 0    1 1    1 2

最佳答案

线性代数?

Cell i,j is touched x<sub>ij</sub> times.

n2 个变量和方程。解决。 O(n^6) 通过高斯方法,可能存在其他更快的方法。

此外,matrix 很特殊,因此可能会使其更快。

关于algorithm - 找到矩阵运算的有效算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12361634/

相关文章:

algorithm - 来自连续流的等概率随机数

database - 二进制搜索如何用于数据库索引

c# - 如何解释 C# 中的伪代码?

c - 中点圆算法不适用于不等中心坐标

algorithm - 合并两个排序的间隔列表

c - 检查二维数组中不连续分组的更好算法

algorithm - 有效分担费用后偿还债务: max 1 transaction per person

algorithm - 快速排序 CLRS 分区总是在 n/3 元素上

python - DP求解0和1个数相等的连续子数组的最大长度

java - 计算抢占式最短作业优先调度算法的平均等待时间