标签:nyoj聪明的kk
3 4 3 1 2 8 5 3 4 6 1 0 2 3
24
#include<cstdio> #include<cstdlib> #include<cstring> #include<queue> int m,n,max,map[25][25],vis[25][25],mov[][2]={1,0,0,1}; int dist[25][25]; void DFS(int x,int y){ int xx,yy; for(int i=0;i<2;++i){ xx=x+mov[i][0]; yy=y+mov[i][1]; if(xx>=0&&xx<m&&yy>=0&&yy<n&&(vis[xx][yy]==0||dist[x][y]+map[xx][yy]>=dist[xx][yy])){ dist[xx][yy]=dist[x][y]+map[xx][yy]; vis[xx][yy]=1; max=dist[xx][yy]>max?dist[xx][yy]:max; DFS(xx,yy); } } } int main() { int a,b,i,j; while(scanf("%d%d",&m,&n)==2){ for(i=0;i<m;++i){ for(j=0;j<n;++j) scanf("%d",&map[i][j]); } max=0; memset(vis,0,sizeof(vis)); memset(dist,0,sizeof(dist)); dist[0][0]=map[0][0]; DFS(0,0); printf("%d\n",max); } return 0; }
标签:nyoj聪明的kk
原文地址:http://blog.csdn.net/r1986799047/article/details/43486085