http://acm.pku.edu.cn/JudgeOnline/problem?id=1088 388K16MSC++1420B2010-02-24 19:53:01 #include<iostream> #include<algorithm> using namespace std; struct vip { int high; int dp; }mp[120][120]; struct point { int x; int y; int hp; }po[14400]; int cmp(point a,point b) { if(a.hp==b.hp) return a.x<b.x; return a.hp<b.hp; } int main() { int n,m,k,i,j,ma; while(scanf("%d%d",&n,&m)!=EOF) { k=0; for(i=0;i<n;i++) for(j=0;j<m;j++) { scanf("%d",&mp[i][j].high); po[k].hp=mp[i][j].high; po[k].x=i; po[k++].y=j; mp[i][j].dp=1; } sort(po,po+k,cmp); ma=0; for(i=0;i<k;i++) { if(po[i].x-1>=0&&mp[po[i].x-1][po[i].y].high>mp[po[i].x][po[i].y].high&&mp[po[i].x-1][po[i].y].dp<mp[po[i].x][po[i].y].dp+1) mp[po[i].x-1][po[i].y].dp=mp[po[i].x][po[i].y].dp+1; if(po[i].x+1<n&&mp[po[i].x+1][po[i].y].high>mp[po[i].x][po[i].y].high&&mp[po[i].x+1][po[i].y].dp<mp[po[i].x][po[i].y].dp+1) mp[po[i].x+1][po[i].y].dp=mp[po[i].x][po[i].y].dp+1; if(po[i].y-1>=0&&mp[po[i].x][po[i].y-1].high>mp[po[i].x][po[i].y].high&&mp[po[i].x][po[i].y-1].dp<mp[po[i].x][po[i].y].dp+1) mp[po[i].x][po[i].y-1].dp=mp[po[i].x][po[i].y].dp+1; if(po[i].y+1<m&&mp[po[i].x][po[i].y+1].high>mp[po[i].x][po[i].y].high&&mp[po[i].x][po[i].y+1].dp<mp[po[i].x][po[i].y].dp+1) mp[po[i].x][po[i].y+1].dp=mp[po[i].x][po[i].y].dp+1; if(ma<mp[po[i].x][po[i].y].dp)ma=mp[po[i].x][po[i].y].dp; } printf("%d/n",ma); } return 0; }