poj 1088 記憶化搜尋

2021-06-27 17:20:43 字數 1076 閱讀 6784

如題:

description

michael喜歡滑雪百這並不奇怪, 因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你不得不再次走上坡或者等待公升降機來載你。michael想知道載乙個區域中最長底滑坡。區域由乙個二維陣列給出。陣列的每個數字代表點的高度。下面是乙個例子

1  2  3  4 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

乙個人可以從某個點滑向上下左右相鄰四個點之一,當且僅當高度減小。在上面的例子中,一條可滑行的滑坡為24-17-16-1。當然25-24-23-...-3-2-1更長。事實上,這是最長的一條。

input

輸入的第一行表示區域的行數r和列數c(1 <= r,c <= 100)。下面是r行,每行有c個整數,代表高度h,0<=h<=10000。

output

輸出最長區域的長度。

sample input

5 5

1 2 3 4 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

sample output

25
len[i][j]表示以i,j開始的最長區域的長度。len[i][j]=max+1。

動歸過程中,狀態被不停地修改,儲存有用的狀態,下次不必重新搜尋,就是記憶化搜尋。使用遞迴實現。

#include

using namespace std;

int map[105][105];

int r,c;

int dir[4][2]=,,,};

int len[105][105];

int dp(int i,int j)}}

len[i][j]=max+1;

return len[i][j];

}int main()

printf("%d\n",max);

}return 0;

}

記憶化搜尋,poj1088

flag i j 表示以現在這個位置為起點的最遠能走的長度,熟悉下遞迴,這個題應該不難,記憶化 include include define max 105 define maxhigh 10005 typedef struct position position move 4 int flag m...

POJ 1088(記憶化搜尋)

滑雪time limit 1000ms memory limit 65536k total submissions 87494 accepted 32785 description michael喜歡滑雪百這並不奇怪,因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你不...

POJ 1088 滑雪 記憶化搜尋

滑雪 time limit 1000ms memory limit 65536k total submissions 79619 accepted 29637 description michael喜歡滑雪百這並不奇怪,因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你...