动态规划(DP),排序的时候使用的还是我自己写的快速排序,地址: http://acm.pku.edu.cn/JudgeOnline/problem?id=1088
#include "stdio.h"
typedef struct
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int h;
int len;
int x;
int y;
}mytype;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) 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)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
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)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
while(low<=high)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(low<p)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(num[low].h>num[p].h) {swap(low,p);p=low;}
low++;
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(high>p)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(num[high].h<num[p].h) {swap(high,p);p=high;}
}
high--;
}
}
return p;
}
void qsort(int left,int right)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int middle;
if(left<right)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
middle=(left+right)/2;
middle=partion(left,right,middle);
qsort(left,middle-1);
qsort(middle+1,right);
}
}
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int r,c,i,j;
int tl,tc,max,mmax;
while(scanf("%d%d",&r,&c)!=EOF)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i=0;i<r;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(j=0;j<c;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d",&temp[i][j]);
}
}
for(i=0;i<r;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(j=0;j<c;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
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++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
max=0;
for(j=0;j<4;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
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)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(number[tl*c+tc].h<num[i].h)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
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;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
24 | 25 | 26 | 27 | 28 | 29 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 |
|
公告
决定从线程开始!!
常用链接
留言簿(6)
随笔档案
搜索
最新评论
![](/images/xml.gif)
阅读排行榜
评论排行榜
|
|