0% found this document useful (0 votes)
7 views1 page

Int Find Largest Square

Uploaded by

enocksodokin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Int Find Largest Square

Uploaded by

enocksodokin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

int **find_largest_square(char **board, int rows, int cols) {

int **dp = malloc(rows * sizeof(int *));


for (int i = 0; i < rows; i++) {
dp[i] = malloc(cols * sizeof(int));
}

int max_size = 0;
int max_row = 0, max_col = 0;

// Algorithme dynamique pour trouver le plus grand carré


for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (board[i][j] == '.') {
if (i == 0 || j == 0) {
dp[i][j] = 1; // Premier ligne ou colonne
} else {
dp[i][j] = 1 + (dp[i-1][j] < dp[i][j-1] ? (dp[i-1][j] < dp[i-1]
[j-1] ? dp[i-1][j] : dp[i-1][j-1]) : (dp[i][j-1] < dp[i-1][j-1] ? dp[i][j-1] :
dp[i-1][j-1])));
}

if (dp[i][j] > max_size) {


max_size = dp[i][j];
max_row = i;
max_col = j;
}
} else {
dp[i][j] = 0; // obstacle
}
}
}

return dp;
}

You might also like