1 Star 7 Fork 2

蔚蔚樱软件开发/AlgoHub

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LargestSquare_DynamicOpt.java 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
ljfirst 提交于 2022-10-31 23:58 +08:00 . feat: update
package Algorithm.dynamic.largestSquare;
/**
* @author 蔚蔚樱
* @version 1.0
* @date 2020/6/3
* @author—Email micromicrohard@outlook.com
* @blogURL https://blog.csdn.net/Micro_Micro_Hard
* @description 动态规划优化 : 一维矩阵
*/
public class LargestSquare_DynamicOpt implements LargestSquare {
public int Solution(int[][] Matrix) {
if (check(Matrix)) {
int MaxSideLength = 0;
//状态矩阵
int raw_bound = Matrix.length;
int column_bound = Matrix[0].length;
int[] statusMatrix = new int[column_bound + 1];
int pre = 0;
int now;
for (int i = 1; i <= raw_bound; i++) {
for (int j = 1; j <= column_bound; j++) {
now = statusMatrix[j];
if (Matrix[i - 1][j - 1] == 1) {
statusMatrix[j] = Math.min(Math.min(now, pre), statusMatrix[j - 1]) + 1;
MaxSideLength = Math.max(MaxSideLength, statusMatrix[j]);
} else {
statusMatrix[j] = 0;
}
pre = now;
}
}
return MaxSideLength * MaxSideLength;
}
return -1;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/micromicrohard/algo-hub.git
git@gitee.com:micromicrohard/algo-hub.git
micromicrohard
algo-hub
AlgoHub
master

搜索帮助