[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; }
相关文章推荐
- evernote导出
- redis sentinel 2节点,停机自动切换
- AAPCS 学习课后练习 - 通过一个小例子来讲解
- 连续特征离散化和归一化
- Github博客地址
- Linux 防火墙配置
- [Coursera]算法基础_Week4_动态规划(1)_Q1
- Python3切换华为hi link设备数据开关
- DVWA系列之11 Brute Force中的密码绕过
- DVWA系列之11 Brute Force中的密码绕过
- Poj3984- dfs -迷宫问题
- MTK校准默认参数修改(2010-3-29 16:16)
- 数据结构问题集锦 - Max Points on a Line问题
- 流程
- Redhat7 配置ipv6
- 分享Python字符串关键点
- [Coursera]算法基础_Week3_递归_Q2
- web工程复制后改名字后遇到问题,怎么解决
- python 多线程学习
- 倍数提高工作效率的 Android Studio 奇技