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 Fly_Sea at 2011-08-13 17:05:19 on Problem 1088
In Reply To:发现自己的代码挺短的,贴一下 Posted by:lvsheng4 at 2011-07-22 16:21:41
> #include<iostream>
> using namespace std;
> 
> #define MAXN 20000
> 
> int map[105][105];
> int f[105][105];
> int x[]={0,0,1,-1};
> int y[]={1,-1,0,0};
> 
> void dfs(int i,int j)
> {
> 	for(int k=0;k<4;k++)
> 	{
> 		if(map[i+x[k]][j+y[k]]>map[i][j] && f[i][j]+1>f[i+x[k]][j+y[k]])
> 		{
> 			f[i+x[k]][j+y[k]]=f[i][j]+1;
> 				dfs(i+x[k],j+y[k]);
> 		}
> 			
> 	}
> }
> 
> int main()
> {
> 	int r,c,s;
> 	while(cin>>r>>c)
> 	{
> 		for(int i=1;i<=r;i++)
> 			for(int j=1;j<=c;j++)
> 				cin>>map[i][j],f[i][j]=1;
> 		for(int i=0;i<=r+1;i++)
> 			map[0][i]=map[r+1][i]=map[i][0]=map[i][c+1]=MAXN;
> 		for(int i=1;i<=r;i++)
> 			for(int j=1;j<=c;j++)
> 				dfs(i,j);
> 		s=0;
> 		for(int i=1;i<=r;i++)
> 			for(int j=1;j<=c;j++)
> 				if(f[i][j]>s)
> 					s=f[i][j];
> 		cout<<s<<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