#include
<
iostream
>
#include
<
limits
>
int
data[
100
][
100
];
int
resu[
100
][
100
];
int
x[
4
]
=
{
-
1
,
0
,
1
,
0
}
;
int
y[
4
]
=
{
0
,
-
1
,
0
,
1
}
;
int
r,c;
bool
isok(
int
i,
int
j )
{
return
( i
>=
0
&&
i
<
r
&&
j
>=
0
&&
j
<
c );
}
int
DP(
int
i,
int
j )
{
int
max
=
0
;
if
( resu[i][j]
!=
0
)
return
resu[i][j];
for
(
int
t
=
0
; t
<
4
;
++
t )
{
if
( isok( i
+
x[t], j
+
y[t] )
&&
data[ i
+
x[t] ][ j
+
y[t] ]
<
data[i][j] )
{
int
m
=
DP( i
+
x[t], j
+
y[t] );
if
( m
>
max ) max
=
m;
}
}
return
max
+
1
;
}
int
main()
{
scanf(
"
%d%d
"
,
&
r,
&
c);
for
(
int
i
=
0
; i
<
r;
++
i )
for
(
int
j
=
0
; j
<
c;
++
j )
scanf(
"
%d
"
,
&
data[i][j] );
memset( resu,
0
,
sizeof
(resu) );
int
max
=
INT_MIN;
for
(
int
i
=
0
; i
<
r;
++
i )
for
(
int
j
=
0
; j
<
c;
++
j )
{
resu[i][j]
=
DP(i,j);
if
( max
<
resu[i][j] ) max
=
resu[i][j];
}
printf(
"
%d\n
"
, max );
return
0
;
}
posted on 2008-10-03 12:29
Darren 阅读(371)
评论(0) 编辑 收藏 引用 所属分类:
动态规划