动态规划(DP),排序的时候使用的还是我自己写的快速排序,地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1088
#include "stdio.h"
typedef struct
{
    
int h;
    
int len;
    
int x;
    
int y;
}
mytype;
int mov[4][2]={0,1,1,0,0,-1,-1,0};
mytype num[
11025];
mytype number[
11025];
int temp[105][105];
void swap(int a,int b)
{
    
int th,tx,ty;
    th
=num[a].h;
    tx
=num[a].x;
    ty
=num[a].y;
    num[a].h
=num[b].h;
    num[a].x
=num[b].x;
    num[a].y
=num[b].y;
    num[b].h
=th;
    num[b].x
=tx;
    num[b].y
=ty;
}

int partion(int low,int high,int p)
{
    
while(low<=high)
    
{
        
if(low<p)
        
{
            
if(num[low].h>num[p].h){swap(low,p);p=low;}
            low
++;
        }

        
else
        
{
            
if(high>p)
            
{
                
if(num[high].h<num[p].h){swap(high,p);p=high;}
            }

            high
--;
        }

    }

    
return p;
}

void qsort(int left,int right)
{
    
int middle;
    
if(left<right)
    
{
        middle
=(left+right)/2;
        middle
=partion(left,right,middle);
        qsort(left,middle
-1);
        qsort(middle
+1,right);
    }

}

int main()
{
    
int r,c,i,j;
    
int tl,tc,max,mmax;
    
while(scanf("%d%d",&r,&c)!=EOF)
    
{
        
for(i=0;i<r;i++)
        
{
            
for(j=0;j<c;j++)
            
{
                scanf(
"%d",&temp[i][j]);
            }

        }

        
for(i=0;i<r;i++)
        
{
            
for(j=0;j<c;j++)
            
{
                num[i
*c+j].x=number[i*c+j].x=i;
                num[i
*c+j].y=number[i*c+j].y=j;
                number[i
*c+j].len=1;
                num[i
*c+j].h=number[i*c+j].h=temp[i][j];
            }

        }

        qsort(
0,r*c-1);
        mmax
=0;
        
for(i=0;i<r*c;i++)
        
{
            max
=0;
            
for(j=0;j<4;j++)
            
{
                tl
=num[i].x+mov[j][0];
                tc
=num[i].y+mov[j][1];
                
if(tc>=0&&tc<r*c&&tl>=0&&tl<r*c)
                
{
                    
if(number[tl*c+tc].h<num[i].h)
                    
{
                        
if(max<number[tl*c+tc].len)max=number[tl*c+tc].len;
                    }

                }

            }

            number[num[i].x
*c+num[i].y].len=max+1;
            
if(mmax<max)mmax=max;
        }

        printf(
"%d\n",mmax+1);
    }

    
return 0;
}