//============================================================================
// Name : 1088.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
typedef struct location {
int height;
struct location* next[4];
int nextNumber;
int step;
} Location;
void connect(Location* a, Location* b) {
if (a->height > b->height) {
a->next[a->nextNumber] = b;
a->nextNumber++;
} else if (b->height > a->height) {
b->next[b->nextNumber] = a;
b->nextNumber++;
}
}
int calStep(Location *loc) {
if (loc->step) {
return loc->step;
} else {
if (loc->nextNumber == 0) {
loc->step = 1;
} else {
int max = 0;
for (int i = 0; i < loc->nextNumber; i++) {
int nstep = calStep(loc->next[i]);
if (max < nstep) {
max = nstep;
}
}
loc->step = max + 1;
}
return loc->step;
}
}
int main() {
int r, c;
cin >> r >> c;
Location loc[r][c];
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++) {
cin >> loc[i][j].height;
loc[i][j].nextNumber = 0;
loc[i][j].step = 0;
if (i > 0) {
connect(&(loc[i - 1][j]), &(loc[i][j]));
}
if (j > 0) {
connect(&(loc[i][j - 1]), &(loc[i][j]));
}
}
int max = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
int nstep = calStep(&loc[i][j]);
if (max < nstep)
max = nstep;
}
}
cout << max << endl;
return 0;
}
poj1088
最新推荐文章于 2019-10-29 22:36:15 发布