Created
April 2, 2020 05:56
-
-
Save niklasjang/25e36aca3318f08b10a44723710ee5f3 to your computer and use it in GitHub Desktop.
[PS][완전탐색][DFS]/[BOJ][1937][욕심쟁이 판다]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <string.h> | |
using namespace std; | |
int n=0, input =0, ans=0; | |
int map[501][501]; | |
int dp[501][501]; | |
bool visited[501][501]; | |
int dx[4] = {0,0,1,-1}; | |
int dy[4] = {1,-1, 0,0}; | |
int max(int a, int b){ | |
return a < b ? b : a; | |
} | |
int dfs(int x, int y){ | |
if(dp[x][y]) return dp[x][y]; | |
int nx=0, ny=0; | |
for(int k=0; k<4; k++){ | |
nx = x + dx[k]; | |
ny = y + dy[k]; | |
if(nx <0 || nx >=n) continue; | |
if(ny <0 || ny >=n) continue; | |
if(map[x][y] >= map[nx][ny]) continue; | |
dp[x][y] = max(dp[x][y], dfs(nx,ny)+1); | |
} | |
return dp[x][y]; | |
} | |
int main (void){ | |
cin.tie(NULL); | |
ios::sync_with_stdio("false"); | |
cin>> n; | |
for(int i=0; i<n; i++){ | |
for(int j=0; j<n; j++){ | |
cin>> map[i][j]; | |
} | |
} | |
memset(dp, 0, sizeof(dp)); | |
for(int i=0; i<n; i++){ | |
for(int j=0; j<n; j++){ | |
ans = max(ans,dfs(i,j)); | |
} | |
} | |
cout << ans + 1<<"\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//시간초과 코드