滑雪
time limit:1000ms
memory limit:65536k
total submissions:107602
accepted:41002
description
michael喜歡滑雪百這並不奇怪, 因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你不得不再次走上坡或者等待公升降機來載你。michael想知道載乙個區域中最長底滑坡。區域由乙個二維陣列給出。陣列的每個數字代表點的高度。下面是乙個例子
1 2 3 4 516 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 5sample output1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
25思路:利用dp思想,利用記憶化搜尋,已搜過的就不再搜了,step[i][j] 儲存的是當前座標i,j可以到達的不含自己的最大距離。
例如:比如2 1,當前是2,那麼可以到達的最大距離為1;(到1)
比如3 2 1,當前是3,那麼可以到達的最大距離為2。(到2、1)
dfs:對每個座標,對上下左右搜尋,取max,作為當前的step[i][j]。
記憶化:對每個step[i][j],當搜尋到該座標時,該座標的step已經有值(搜尋過了),肯定是最優的,那麼直接返回該step值就可以了。
**如下:
#include #include #include using namespace std;
const int maxn=110;
int mp[maxn][maxn];
int step[maxn][maxn];
int dx[4]=;
int dy[4]=;
int n,m;
bool judge(int x,int y)
int dfs(int x,int y)//當前位置所能到達的最大距離
}return step[x][y];
}int main()
printf("%d",ans+1);//注意+1,因為本身也是序列裡的一員(第乙個)
return 0;
}
POJ 1088 滑雪 DFS(記憶化)
滑雪time limit 1000ms memory limit 65536k total submissions 80532 accepted 30038 description michael喜歡滑雪百這並不奇怪,因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你不...
POJ1088 滑雪 DFS 記憶化
題目描述 michael喜歡滑雪百這並不奇怪,因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你不得不再次走上坡或者等待公升降機來載你。michael想知道載乙個區域中最長底滑坡。區域由乙個二維陣列給出。陣列的每個數字代表點的高度。下面是乙個例子 1 2 3 4 5 1...
POJ 1088 滑雪 DFS 記憶化搜尋
滑雪 time limit 1000ms memory limit 65536k total submissions 75081 accepted 27855 description michael喜歡滑雪百這並不奇怪,因為滑雪的確很刺激。可是為了獲得速度,滑的區域必須向下傾斜,而且當你滑到坡底,你...