sss胜利 @ 2019-07-23 10:04:17
using namespace std; int c,r,h[110][110],ans[110][110]; int dfs(int x,int y) { if(h[x+1][y] >= h[x][y] && h[x][y+1] >= h[x][y] && h[x-1][y] >= h[x][y] && h[x][y-1] >= h[x][y]) { return ans[x][y] = 1; } if(ans[x][y]) { return ans[x][y]; } if(h[x+1][y] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x+1,y)+1); if(h[x][y-1] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x,y-1)+1); if(h[x][y+1] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x,y+1)+1); if(h[x-1][y] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x-1,y)+1); } int main() { int i,j; scanf("%d%d",&r,&c); for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { scanf("%d",&h[i][j]); } } for(i=0;i<=c+1;i++) { h[0][i] = h[r+1][i] = 1000000000; h[i][0] = h[i][c+1] = 1000000000; } for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { dfs(i,j); } } int mx = -1; for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { mx = max(mx,ans[i][j]); //printf("%d %d %d\n",i,j,ans[i][j]); } } printf("%d",mx); return 0; }
by sss胜利 @ 2019-07-23 10:06:22
include<cstdio>
include<cstring>
include<cmath>
include<string>
include<algorithm>
include<stack>
include<queue>
using namespace std; int c,r,h[110][110],ans[110][110]; int dfs(int x,int y) { if(h[x+1][y] >= h[x][y] && h[x][y+1] >= h[x][y] && h[x-1][y] >= h[x][y] && h[x][y-1] >= h[x][y]) { return ans[x][y] = 1; } if(ans[x][y]) { return ans[x][y]; } if(h[x+1][y] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x+1,y)+1); if(h[x][y-1] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x,y-1)+1); if(h[x][y+1] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x,y+1)+1); if(h[x-1][y] < h[x][y]) ans[x][y] = max(ans[x][y] , dfs(x-1,y)+1); } int main() { int i,j; scanf("%d%d",&r,&c); for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { scanf("%d",&h[i][j]); } } for(i=0;i<=c+1;i++) { h[0][i] = h[r+1][i] = 1000000000; h[i][0] = h[i][c+1] = 1000000000; } for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { dfs(i,j); } } int mx = -1; for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { mx = max(mx,ans[i][j]); } } printf("%d",mx); return 0; }
by Smile_Cindy @ 2019-07-23 10:10:50
请不要使用Markdown来强调头文件的重要性。
by 1saunoya @ 2019-07-23 10:11:33
希望更丰富的展现?使用Markdown
by tythen @ 2019-07-23 14:59:32
帮楼主beautify了一下,这下他的代码可以读了:
int c, r, h[110][110], ans[110][110];
int dfs(int x, int y) {
if (h[x + 1][y] >= h[x][y] && h[x][y + 1] >= h[x][y] && h[x - 1][y] >= h[x][y] && h[x][y - 1] >= h[x][y]) {
return ans[x][y] = 1;
}
if (ans[x][y]) {
return ans[x][y];
}
if (h[x + 1][y] < h[x][y]) ans[x][y] = max(ans[x][y], dfs(x + 1, y) + 1);
if (h[x][y - 1] < h[x][y]) ans[x][y] = max(ans[x][y], dfs(x, y - 1) + 1);
if (h[x][y + 1] < h[x][y]) ans[x][y] = max(ans[x][y], dfs(x, y + 1) + 1);
if (h[x - 1][y] < h[x][y]) ans[x][y] = max(ans[x][y], dfs(x - 1, y) + 1);
}
int main() {
int i, j;
scanf("%d%d", & r, & c);
for (i = 1; i <= r; i++) {
for (j = 1; j <= c; j++) {
scanf("%d", & h[i][j]);
}
}
for (i = 0; i <= c + 1; i++) {
h[0][i] = h[r + 1][i] = 1000000000;
h[i][0] = h[i][c + 1] = 1000000000;
}
for (i = 1; i <= r; i++) {
for (j = 1; j <= c; j++) {
dfs(i, j);
}
}
int mx = -1;
for (i = 1; i <= r; i++) {
for (j = 1; j <= c; j++) {
mx = max(mx, ans[i][j]);
}
}
printf("%d", mx);
return 0;
}
debug的事情就交给其他人吧,逃