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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

POJ 1088-滑雪

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

矩陣里的數字代表當前點的高度,只能從高的點滑到低的點,求最長能滑的距離。初始點

不規定。我們可以向每個點的四周搜索,能走則就在當前距離加1。并將已經求的值保存在

二維數組中。(記憶化搜索)

?

/*Accepted 252K 47MS C++ 1158B 2012-07-23 16:13:17*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std;const int MAXN = 105; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0};int map[MAXN][MAXN], d[MAXN][MAXN]; int R, C, ans;void init() {int i, j;for( i = 1; i <= R; i ++)for( j = 1; j <= C; j ++){scanf( "%d", &map[i][j]);d[i][j] = -1;} } int dfs( int x, int y) {int i, ans, nx, ny;if( d[x][y] > 0) return d[x][y];ans = 0;for( i = 0; i < 4; i ++){nx = x + dx[i];ny = y + dy[i];if( map[x][y] <= map[nx][ny] || nx < 1 || nx > R || ny < 1 || ny > C)continue;ans = max( ans, dfs(nx, ny) + 1);}return ans; }int main() {int i, j;while( scanf( "%d%d", &R, &C) == 2){init();ans = 0;for( i = 1; i <= R; i ++)for( j = 1; j <= C; j ++){d[i][j] = dfs(i, j);ans = max( ans, d[i][j]);}printf( "%d\n", ans + 1);}return 0; }

?

?下面的代碼TLE了

#include<cstdio>
#include<cstring>
#include<cstdlib>
#define MAXN 105
int R, C, lgst;
int map[MAXN][MAXN];
const int dx[] = { 1, -1, 0, 0};
const int dy[] = { 0, 0, 1, -1};

void dfs( int x, int y, int dep)
{
if( x < 0 || x >= R || y < 0 || y >= C) return;
if( lgst < dep) lgst = dep;
for( int d = 0; d < 4; d ++)
{
int nx = x + dx[d];
int ny = y + dy[d];
if( map[x][y] > map[nx][ny])
dfs( nx, ny, dep + 1);
}
}

void init()
{
for( int i = 0; i < R; i ++)
for( int j = 0; j < C; j ++)
{
scanf( "%d", &map[i][j]);
}
}

int main()
{
scanf( "%d%d", &R, &C);
init();
lgst = 1;
for( int i = 0; i < R; i ++)
for( int j = 0; j < C; j ++)
dfs( i, j, 1);
printf( "%d\n", lgst);
return 0;
}

?

轉載于:https://www.cnblogs.com/Yu2012/archive/2011/12/15/2289561.html

總結

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

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