dp問題 滑雪

2021-07-30 00:09:39 字數 1240 閱讀 2898

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 51 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

#include #include #include #include using namespace std;

#include #include #include using namespace std;

int n,m;

int minn,maxx;

int a[105][105];

int dp[105][105];

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

struct node

point[10005];

bool cmp( node a,node b)

int main()

for(int i=1;i<=n;i++)

for(int j=1;j<=m;j++)

dp[i][j]=1;

sort(point+1,point+1+n*m,cmp); //將高度從小到大排序 然後找遞增的高度

for(int l=1;l<=m*n;l++) }

maxx=0;

for(int i=1;i<=n;i++)

for(int j=1;j<=m;j++)

if(dp[i][j]>maxx) maxx=dp[i][j];

cout<

滑雪(DP 搜尋)

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

滑雪(dp 深搜)

time limit 1 ms memory limit 128 mb difficulty 3 trs喜歡滑雪。他來到了乙個滑雪場,這個滑雪場是乙個矩形,為了簡便,我們用r行c列的矩陣來表示每塊地形。為了得到更快的速度,滑行的路線必須向下傾斜。例如樣例中的那個矩形,可以從某個點滑向上下左右四個相鄰...

入門dp 滑雪, 串

problem p1434 shoi2002 滑雪 solution d p i j max if a i 1 j 1 i j dp left i right left j right max left if a left i pm 1 right left j pm 1 right dp i j ...