Create 1088.cpp

This commit is contained in:
Kirigaya Kazuto 2017-03-16 22:41:46 +08:00 committed by GitHub
parent 14e5dec9be
commit ef48b33f43

74
POJ/1088.cpp Normal file
View File

@ -0,0 +1,74 @@
#include <iostream>
using namespace std;
#define MAXN 101
int R,C;
int mp[MAXN][MAXN];
int dp[MAXN][MAXN];
int dfs(int line,int col)
{
if(dp[line][col]!=0) return dp[line][col];
if(line+1<R&&mp[line][col]>mp[line+1][col])
{
dp[line][col]=max(dp[line][col],dfs(line+1,col));
}
if(line-1>=0&&mp[line][col]>mp[line-1][col])
{
dp[line][col]=max(dp[line][col],dfs(line-1,col));
}
if(col+1<C&&mp[line][col]>mp[line][col+1])
{
dp[line][col]=max(dp[line][col],dfs(line,col+1));
}
if(col-1>=0&&mp[line][col]>mp[line][col-1])
{
dp[line][col]=max(dp[line][col],dfs(line,col-1));
}
dp[line][col]++;
return dp[line][col];
}
int main()
{
cin>>R>>C;
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
cin>>mp[i][j];
}
}
int maxval=-1;
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
maxval=max(maxval,dfs(i,j));
}
}
/*
for(int i=0;i<R;i++)
{
for(int j=0;j<C;j++)
{
maxval=max(maxval,dp[i][j]);
}
}
*/
cout<<maxval<<endl;
return 0;
}