BNUOJ 1207 滑雪
生活随笔
收集整理的這篇文章主要介紹了
BNUOJ 1207 滑雪
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
滑雪
Time Limit:?1000ms Memory Limit:?65536KB This problem will be judged on PKU. Original ID:?108864-bit integer IO format:?%lld????? Java class name:?Main 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 9Sample Output
25Source
SHTSC 2002 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <ctype.h> 8 #include <cmath> 9 #include <algorithm> 10 #define LL long long 11 using namespace std; 12 int rows,cols; 13 int table[101][101],rec[101][101]; 14 int solve(int x,int y,int height){ 15 if(x < 0 || y < 0 || x >= rows || y >= cols || table[x][y] <= height) 16 return 0; 17 if(rec[x][y]) return rec[x][y]; 18 rec[x][y] = max(rec[x][y],solve(x-1,y,table[x][y])); 19 rec[x][y] = max(rec[x][y],solve(x+1,y,table[x][y])); 20 rec[x][y] = max(rec[x][y],solve(x,y+1,table[x][y])); 21 rec[x][y] = max(rec[x][y],solve(x,y-1,table[x][y])); 22 return ++rec[x][y]; 23 } 24 int main(){ 25 int i,j,mx,temp; 26 scanf("%d %d",&rows,&cols); 27 for(i = 0; i < rows; i++){ 28 for(j = 0; j < cols; j++){ 29 scanf("%d",table[i]+j); 30 rec[i][j] = 0; 31 } 32 } 33 for(mx = i = 0; i < rows; i++){ 34 for(j = 0; j < cols; j++){ 35 temp = solve(i,j,INT_MIN); 36 if(temp > mx) mx = temp; 37 } 38 } 39 printf("%d\n",mx); 40 return 0; 41 } View Code?
轉載于:https://www.cnblogs.com/crackpotisback/p/3835738.html
總結
以上是生活随笔為你收集整理的BNUOJ 1207 滑雪的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Loading 遮蔽层 简单实现。
- 下一篇: 左右替换循环