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

Re:改成这样就过了

Posted by canism at 2013-07-17 16:42:55 on Problem 1088
In Reply To:Re:代码升级,我同学这样写的AC了,为什么我的还是超时? Posted by:kanxue2002 at 2013-04-02 19:33:56
#include <iostream>
using namespace std;
int map[105][105];
int len[105][105];
int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
int m,n;
int find(int x,int y){
    if(len[x][y]>0)
        return len[x][y];
	int tx,ty;
	for(int k=0;k<4;++k){
        tx=x+dir[k][0];
		ty=y+dir[k][1];
		if(tx>=1&&ty>=1&&tx<=m&&ty<=n){
            if(map[x][y]>map[tx][ty]){
            if(len[x][y]<find(tx,ty))
                len[x][y]=find(tx,ty);
            }
		}
	}
	return len[x][y]=len[x][y]+1;
}
int main()
{
    int i,j;
	int max;
	while(cin>>m>>n){
		max=-1;
		for(i=1;i<=m;++i)
			for(j=1;j<=n;++j){
				cin>>map[i][j];
				len[i][j]=0;
			}
		for(i=1;i<=m;++i)
			for(j=1;j<=n;++j){
				find(i,j);
				if(max<len[i][j])
					max=len[i][j];
				}
		cout<<max<<endl;
	}
    return 0;
}

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