测试数据都对,老掉牙WA.

测试数据都对,老WA...

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
int x;
int y;
int value;
}a[10100];
int cmp(const void *a,const void *b){
struct node *p1,*p2;
p1=(struct node *)a;
p2=(struct node *)b;
if(p1->value>p2->value)
return 1;
else
return -1;
}
int value[110][110];
int f[110][110];
int main()
{
int r,c,i,j,k;
int cx,cy,maxh;
scanf("%d%d",&r,&c);
memset(f,sizeof(f),0);
memset(value,sizeof(value),0);
k=0;
maxh=0;
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
scanf("%d",&value[i][j]);
a[k].value=value[i][j];
a[k].x=i;
a[k].y=j;
k++;
}
}
qsort(a,k,sizeof(struct node),cmp);
for(i=0;i<k;i++){
cx=a[i].x;
cy=a[i].y;
if(cx>1){
if(a[i].value<value[cx-1][cy]&&f[cx][cy]>=f[cx-1][cy])
f[cx-1][cy]=f[cx][cy]+1;
}
if(cx<c){
if(a[i].value<value[cx+1][cy]&&f[cx][cy]>=f[cx+1][cy])
f[cx+1][cy]=f[cx][cy]+1;
}
if(cy>1){
if(a[i].value<value[cx][cy-1]&&f[cx][cy]>=f[cx][cy-1])
f[cx][cy-1]=f[cx][cy]+1;
}
if(cy<r){
if(a[i].value<value[cx][cy+1]&&f[cx][cy]>=f[cx][cy+1])
f[cx][cy+1]=f[cx][cy]+1;
}
}
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
if(f[i][j]>maxh)
maxh=f[i][j];
}
}
if(maxh!=0)
maxh++;
printf("%d\n",maxh);
//system("pause");
return 0;
}

------解决方案--------------------
哎,楼主自己去调试吧