日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 1088

發布時間:2023/12/18 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ 1088 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

記憶化搜索啊

?

或者直接對高度排序啊,這樣就會先更新步數少的,后更新步數多的了,就可以直接利用先前已經得到的值了

?

?

1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <queue> 5 #include <vector> 6 #define max(x, y) (x > y ? x : y) 7 #define min(x, y) (x > y ? y : x) 8 #define INF 0x3f3f3f3f 9 #define MOD 1000000007 10 #define Yes printf("Yes\n") 11 #define No printf("No\n") 12 using namespace std; 13 typedef long long LL; 14 typedef pair<int, int> PII; 15 16 int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; 17 18 int h, w; 19 const int maxn = 1e2 + 10; 20 21 int hei[maxn][maxn]; 22 int ans[maxn][maxn]; 23 24 struct node { 25 int x, y, h; 26 }map[maxn * maxn]; 27 28 29 bool cmp(const node& A, const node& B) { 30 return A.h < B.h; 31 } 32 33 int main(int argc, const char * argv[]) { 34 int cnt = 0; 35 scanf("%d%d", &h, &w); 36 for (int i = 1; i <= h; i++) { 37 for (int j = 1; j <= w; j++) { 38 scanf("%d", &hei[i][j]); 39 map[cnt].x = i, map[cnt].y = j, map[cnt].h = hei[i][j]; 40 cnt++; 41 ans[i][j] = 1; 42 } 43 } 44 sort(map, map + cnt, cmp); 45 for (int i = 0; i < cnt; i++) { 46 int x = map[i].x, y = map[i].y; 47 for (int j = 0; j < 4; j++) { 48 int nx = x + dx[j], ny = y + dy[j]; 49 if (hei[x][y] > hei[nx][ny]) { 50 ans[x][y] = max(ans[x][y], ans[nx][ny] + 1); 51 } 52 } 53 } 54 int res = 0; 55 for (int i = 1; i <= h; i++) { 56 for (int j = 1; j <= w; j++) { 57 res = max(res, ans[i][j]); 58 } 59 } 60 printf("%d\n", res); 61 return 0; 62 }

?

轉載于:https://www.cnblogs.com/xFANx/p/7260387.html

總結

以上是生活随笔為你收集整理的POJ 1088的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。