| ||||||||||
| 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 | |||||||||
大虾帮我检查下,谢谢了!// POJ 1088
#include<iostream>
using namespace std;
const int way[4][2]={0,1,0,-1,-1,0,1,0};
int mapheight[110][110];
int max(int* a)
{
int i,max=a[0];
for(i=1;i<4;i++)
if(a[i]>max)
max=a[i];
return max;
}
int count(int map[110][110],int m,int n,int x,int y)
{
int i,height;
int fourpozitionmax[4];
if(x<0||x>m||y<0||y>n) return 0;
if((height=mapheight[x][y])>0) return height;
for(i=0;i<4;i++)
{
if(map[x][y]>map[x+way[i][0]][y+way[i][1]])
fourpozitionmax[i]=count(map,m,n,x+way[i][0],y+way[i][1]);
else fourpozitionmax[i]=0;
}
mapheight[x][y]=(height=max(fourpozitionmax)+1);
return height;
}
int main()
{
int map[110][110];
int i,j,m,n,x,y,maxheight=0,height;
cin>>m>>n;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
mapheight[i][j]=-1;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>map[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if((height=count(map,m,n,i,j))>maxheight)
maxheight=height;
cout<<maxheight;
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator