Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
额,这个ac,复杂度是O(r*c),分享分享。#include<stdio.h> int r,c; long f[10004],tt; int p[10004],pos[10004],poss[10004],pp[5]; int maxx(int a,int b) { if (a>b) return a; else return b; } void qsort(int a,int b) { int i,j,tmp,k; i=a;j=b; k=p[(i+j)/2]; while (i<=j) { while (p[i]<k) i++; while (p[j]>k) j--; if(i<=j) { tmp=p[i];p[i]=p[j];p[j]=tmp; tmp=pos[i];pos[i]=pos[j];pos[j]=tmp; poss[pos[i]]=i;poss[pos[j]]=j; i++;j--; } } if (a<j) qsort(a,j); if (i<b) qsort(i,b); } int main() { int i,j; int max,tot; tot=0; scanf("%d%d",&r,&c); for (i=1;i<=r;i++) for (j=1;j<=c;j++) { scanf("%d",&tt); tot++; p[tot]=tt; pos[tot]=tot; poss[tot]=tot; } qsort(1,tot); max=0; for (i=1;i<=tot;i++) { f[i]=1; pp[1]=pos[i]-c;pp[2]=pos[i]+1;pp[3]=pos[i]-1;pp[4]=pos[i]+c; for (j=1;j<=4;j++) { if ((pp[j]<=tot)&&(pp[j]>=1)&&(p[poss[pp[j]]]<p[i])) { if ((j==2)&&(pp[j]%c==1)) continue; if ((j==3)&&(pp[j]%c==0)) continue; f[i]=maxx(f[i],f[poss[pp[j]]]+1); } } max=maxx(max,f[i]); } printf("%d\n",max); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator