您的位置:首页 > 其它

[Coursera]算法基础_Week4_动态规划(1)_Q2

2015-12-13 15:57 295 查看
#include <iostream>
#include <set>
using namespace std;
#define INF 1000000
struct Point
{
int h;
int x, y;
bool operator<(const Point& P)const { return h < P.h; }
Point(int h_, int x_, int y_) :x(x_), y(y_), h(h_) {}
};
int main() {
multiset<Point> map;
multiset<int> hight;
int R, C;
cin >> R >> C;
int H[102][102], L[102][102];
for (int i = 1; i <= R; i++) {
for (int j = 1; j <= C; j++) {
cin >> H[i][j];
map.insert(Point(H[i][j],i,j));
L[i][j] = 1;
}
H[i][0] = INF; H[i][C + 1] = INF;
}
for (int j = 1; j <= C; j++) {
H[0][j] = INF; H[R + 1][j] = INF;
}
for (multiset<Point>::iterator p = map.begin(); p != map.end(); p++) {
multiset<int> temp;
int f = 0;
if (p->h > H[p->x][p->y + 1])
temp.insert(L[p->x][p->y + 1]), f = 1;
if (p->h > H[p->x][p->y - 1])
temp.insert(L[p->x][p->y - 1]), f = 1;
if (p->h > H[p->x + 1][p->y])
temp.insert(L[p->x + 1][p->y]), f = 1;
if (p->h > H[p->x - 1][p->y])
temp.insert(L[p->x - 1][p->y]), f = 1;
if (f) {
multiset<int>::iterator te = temp.end();
te--;
L[p->x][p->y] = *te + 1;
}
hight.insert(L[p->x][p->y]);
}
multiset<int>::iterator h = hight.end();
h--;
cout << *h << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: