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

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值