Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大虾帮我检查下,谢谢了!

Posted by stupidjohn at 2010-04-17 21:34:31 on Problem 1088
// 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator