POJ1088 滑雪 動態規劃 深搜DFS

2021-07-25 21:08:13 字數 1582 閱讀 1958

題目:

滑雪

time limit:1000ms

memory limit:65536k

total submissions:94177

accepted:35668

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
source

shtsc 2002

[submit]   [go back]   [status]   [discuss]

思路:

一開始用搜尋寫的,不管怎麼剪枝都超時不ac。。沒辦法了,就用dp的方法,儲存每一步所能達到的最大狀態

**1(搜尋,poj未ac(超時),在nyoj上可以ac):

#include #include #include #include #include #include #include #include #define mem(a,b) memset(a,b,sizeof(a))

using namespace std;

int map[110][110];

int go[4][2]= ,,,};//四個方向

int ans;

int r,c,step,num;

struct node

a[20000];//讓搜尋的順序從最大的山依次往下搜尋,然而還是超時

bool cmp(node x,node y)

void dfs(int x,int y)

,,,};

int dfs(int x,int y)

dp[x][y]++;//當前狀態的步數加一

return dp[x][y];

}int main()

}

優化時間很重要~

動態規劃 POJ 1088 滑雪

意思就是把所有點存下來,按照高度排個序,然後從小到大列舉,然後判斷當前的點的四個方向有沒有存在經過當前點更優的情況,並且那個點的高度比當前點的高度要高如果存在就更新,因為根據大小排了序,所以不會出現不會出現乙個點重複統計的情況那麼複雜度是o n2 include include include us...

動態規劃 POJ1088 滑雪問題

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

POJ 1088 滑雪 (深搜 DP)

題目描述 input 第一行輸入兩個數n,m代表滑梯範圍行n和列m 1 n,m 100 下面是n行,每行有m個整數,代表高度h,0 h 20000 output 輸出乙個值,代表glory能夠在滑滑梯上面滑行的最長長度是多少 sample input 3 39 1 2 5 6 7 8 4 3 sam...