码迷,mamicode.com
首页 > 其他好文 > 详细

poj 1088

时间:2014-08-12 18:18:14      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:os   io   for   amp   ios   sp   poj   dp   

hnldyhy(303882171) 11:28:19
poj 1088
//DP

#include <iostream>
using namespace std;

int a[102][102],b[102][102];
int r, c,ans;
int f( int i, int j )
{ int max=1,t;
if( b[i][j] > 1 ) return b[i][j];
if( i + 1 <= r && a[i][j] > a[i+1][j] )
{ t = f( i + 1, j ) + 1;
if( max < t ) max = t;
}
if( j + 1 <= c && a[i][j] > a[i][j+1] )
{ t = f( i, j + 1 ) + 1;
if( max < t ) max = t;
}
if( i - 1 > 0 && a[i][j] > a[i-1][j] )
{ t = f( i - 1, j ) + 1;
if( max < t ) max = t;
}
if( j - 1 > 0 && a[i][j] > a[i][j-1] )
{ t = f( i, j - 1 ) + 1;
if( max < t) max = t;
}
return max;
}

int main()
{ int i,j;
cin >> r >> c;
for ( i = 1; i <= r; ++i )
for ( j = 1; j <= c; ++j )
{ cin >> a[i][j]; b[i][j] = 1; }
ans = 1;
for( i = 1; i <= r; ++i )
for( j = 1; j <= c; ++j )
{ b[i][j] = f( i, j );
if( ans < b[i][j] ) ans = b[i][j];
}
cout << ans <<endl;
}

 

poj 1088,布布扣,bubuko.com

poj 1088

标签:os   io   for   amp   ios   sp   poj   dp   

原文地址:http://www.cnblogs.com/2014acm/p/3907679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!