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 |
DP怎么改都是WA..高手帮忙看看吧,要疯了..#include "stdio.h" #include "string.h" typedef struct { int num; int x,y; int dp; }ARR; int rr,cc; int ans,max; ARR arr[10005]; void swap(ARR *za,ARR *zb) { ARR temp; temp=*za; *za=*zb; *zb=temp; } void qsort(int zl,int zr) { int js1,js2,js3,js4; if (zl<zr) { js1=zl-1; for (js2=zl;js2<zr;js2++) { if (arr[js2].num>arr[zr].num) { js1++; swap(&arr[js2],&arr[js1]); } } js1++; swap(&arr[js1],&arr[zr]); qsort(zl,js1-1); qsort(js1+1,zr); } } int main() { int a,b,c,d,e,f,g; d=0; ans=0; memset(arr,0,sizeof(ARR)*10005); scanf("%d %d",&rr,&cc); for (a=0;a<cc;a++) { for (b=0;b<rr;b++) { scanf("%d",&c); arr[d].x=a; arr[d].y=b; arr[d].num=c; d++; } } qsort(0,d-1); /* for (a=0;a<d;a++) */ /* { */ /* for (b=a+1;b<d;b++) */ /* { */ /* if (arr[a].num<arr[b].num) */ /* { */ /* swap(&arr[a],&arr[b]); */ /* } */ /* } */ /* } */ for (a=0;a<d;a++) { max=0; for (b=0;b<a;b++) { if ( (( ( arr[a].x==arr[b].x ) && abs( arr[a].y-arr[b].y )==1) || ( ( arr[a].y==arr[b].y ) && (abs(arr[a].x-arr[b].x)==1))) &&arr[b].num>arr[a].num&&arr[b].dp>max) { max=arr[b].dp; } } arr[a].dp=max+1; if (arr[a].dp>ans) { ans=arr[a].dp; } } printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator