From 3f8c5715f8e68256cacb9909d3a76788937b2da0 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Thu, 21 Aug 2025 22:28:23 +0900 Subject: [PATCH] 20250821 baekjoon --- code_study/Baekjoon/c/14500.c | 84 +++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 code_study/Baekjoon/c/14500.c diff --git a/code_study/Baekjoon/c/14500.c b/code_study/Baekjoon/c/14500.c new file mode 100644 index 0000000..723fa77 --- /dev/null +++ b/code_study/Baekjoon/c/14500.c @@ -0,0 +1,84 @@ +#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]); + } + } +} \ No newline at end of file