- 清帝之惑之顺治
- 2014-04-07 15:55:55 @
#include <cstdio>
#include <iostream>
using namespace std;
int map[510][510];
int f[510][510];
const int px[4] = {-1, 0, 0, 1};
const int py[4] = {0, -1, 1, 0};
int n, m, ans = 0;
int dfs(int x, int y){
f[x][y] = 1;
for (int i = 0;i < 4; ++i){
if (x + px[i] < 1 || y + py[i] < 1 || x + px[i] > n || y + py[i] > m)
continue;
if (map[x + px[i]][y + py[i]] > map[x][y])
continue;
if (!f[x + px[i]][y + py[i]])
dfs(x + px[i], y + py[i]);
f[x][y] = max(f[x][y], f[x + px[i]][y + py[i]] +1);
}
}
int main(){
scanf("%d %d", &n, &m);
for (int i = 1;i <= n; ++i)
for (int j = 1;j <= m; ++j)
scanf("%d", &map[i][j]);
for (int i = 1;i <= n; ++i)
for (int j = 1;j <= m; ++j)
if (!f[i][j])
dfs(i, j);
for (int i = 1;i <= n; ++i)
for (int j = 1;j <= m; ++j)
ans = max(ans, f[i][j]);
printf("%d\n", ans);
}
1 条评论
-
tlyangwj LV 8 @ 2017-02-16 17:05:05
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<cctype>
using namespace std;
struct node{
int ii,jj,hh;
}dian[300000];
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
bool cmp(node xx,node yy)
{return xx.hh<yy.hh;}
int ma[600][600],dp[600][600];
int main()
{
int R,C,kp=0;scanf("%d%d",&R,&C);
for (int i=1;i<=R;i++)
for (int j=1;j<=C;j++)
{
scanf("%d",&ma[i][j]);
dian[kp].hh=ma[i][j];
dian[kp].ii=i;dian[kp].jj=j;
kp++;
}
sort(dian,dian+kp,cmp);
int a,b,x,y,ans=0;
for (int i=0;i<kp;i++)
{
a=dian[i].ii;b=dian[i].jj;
for (int j=0;j<4;j++)
{
x=a+xx[j];y=b+yy[j];
if (x&&y&&x<=R&&y<=C&&ma[x][y]<ma[a][b])
dp[a][b]=max(dp[x][y],dp[a][b]);
}
dp[a][b]++;
ans=max(ans,dp[a][b]);
}
printf("%d\n",ans);
return 0;
}
- 1