1 Star 7 Fork 2

蔚蔚樱软件开发/AlgoHub

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LargestSquare_Dynamic.java 1.19 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_Dynamic 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[raw_bound + 1][column_bound + 1];
for (int i = 1; i <= raw_bound; i++) {
for (int j = 1; j <= column_bound; j++) {
if (Matrix[i - 1][j - 1] == 1) {
statusMatrix[i][j] = Math.min(Math.min(statusMatrix[i - 1][j - 1], statusMatrix[i - 1][j]),
statusMatrix[i][j - 1]) + Matrix[i - 1][j - 1];//Matrix[i - 1][j - 1] 就是 1
MaxSideLength = Math.max(MaxSideLength, statusMatrix[i][j]);
}
}
}
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

搜索帮助