洛谷P1434 SHOI2002 滑雪

2022-03-14 22:28:05 字數 1932 閱讀 2596

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(從24開始,在1結束)。當然25-24-23-...-3-2-1更長。事實上,這是最長的一條。

輸入的第一行為表示區域的二維陣列的行數r和列數c(1≤r,c≤100)。下面是r行,每行有c個數,代表高度(兩個數字之間用1個空格間隔)。

輸出區域中最長滑坡的長度。

輸入 #1複製

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

輸出 #1複製

25

解析:

記憶化搜尋

輸入的是g陣列

在記錄答案時使用的是f陣列

一開始f陣列都初始化為1

然後兩重迴圈從每乙個點都開始搜一遍

注意限定條件是只能從大的滑向小的,是嚴格小於,尋求最大值。

爆搜可以得到90pts的好成績

1 #include2 #include3 #include4 #include5 #include

6 #include7 #include8 #include9 #include10 #include

11 #include12 #include13 #include14

#define re register

15#define max 110

16#define d double

17#define gc getchar

18 inline int

read()

21while(isdigit(p))

22return f?-a:a;23}

24int n,m,g[max][max],ans=1;25

bool vis[max][max]=;

26void dfs(int x,int y,int

step)

2738

intmain()

39

90分爆搜

1 #include2 #include3 #include4 #include5 #include

6 #include7 #include8 #include9 #include10 #include

11 #include12 #include13 #include14

#define re register

15#define max 110

16#define d double

17#define gc getchar

18 inline int

read()

1922

while(isdigit(p))

23return f?-a:a;24}

25int n,m,g[max][max],ans=1

,f[max][max];

26int dfs(int x,int

y)27

40int

main()

41

ac **

洛谷 P1434 SHOI2002 滑雪

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

洛谷 P1434 SHOI2002 滑雪

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

洛谷 P1434 SHOI2002 滑雪

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