#include #include #include int max(int a, int b); void dfs(int** arr, bool** visited, int x, int y, int n, int m, int currentSum, int* currentMax, int depth); void T_block_Search(int** arr, int n, int m, int* currentMax); int main(){ int N, M; scanf("%d %d",&N, &M); int** canvas = (int**)malloc(sizeof(int*)*N); bool** visited = (bool**)malloc(sizeof(bool*)*N); for(int i=0; ib) ? a : b; } void dfs(int** arr, bool** visited, int x, int y, int n, int m, int currentSum, int* currentMax, int depth){ if(depth==4) { *currentMax = max(currentSum, *currentMax); return; } int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; for(int i=0; i<4; i++){ int nx = x + dx[i]; int ny = y + dy[i]; if(nx<0 || ny<0 || nx>=m || ny>=n || visited[ny][nx]) continue; visited[ny][nx] = true; dfs(arr, visited, nx, ny, n, m, currentSum + arr[ny][nx], currentMax, depth + 1); visited[ny][nx] = false; } } void T_block_Search(int** arr, int n, int m, int* currentMax){ for(int y=0; y=1 && y+1=1 && x+1=1 && y>=1 && y+1=1 && x+1=1) *currentMax = max(*currentMax, arr[y][x]+arr[y][x+1]+arr[y][x-1]+arr[y-1][x]); } } }