Poj1088-Ski
Treat each ski spot as a starting point, starting from the lowest point by four weeks. The length of the longest path reaching this point is noted.
In theory, you can also see each point as the end point, counting from the top, and interested to try.
1 //Classic dp-Ski from high to low altitude-find the longest road2 //memory:372k time:32 Ms3#include <iostream>4#include <cstring>5#include <cstdio>6#include <algorithm>7 using namespacestd;8 #defineMax (x, y) (() > (y)? ( x):(y))9 #defineMAX 105Ten intRow, col, Len; One intMap[max][max];//Standard Records A intmov[4][2] = { {1,0}, { -1,0}, {0,1}, {0, -1 } }; - intD[max][max];//dp[] - intans; the /*Individual Point Properties*/ - structnode{ - intx, y;//coordinates (x, y) - intValue//Altitude +}node[max*MAX]; - BOOL operator< (ConstNode A,ConstNode b) + { A returnA.value <B.value; at } - voidDP () - { -Ans =0; -memset (D,0,sizeof(d)); - for(inti =0; i < Len; i++) in { - intx = node[i].x, y =node[i].y; to for(intj =0; J <4; J + +) + { - inttx = x + mov[j][0]; the intty = y + mov[j][1]; * if(TX >=0&& TX < row && Ty >=0&& Ty <Col) $ {Panax Notoginseng if(Map[x][y] >Map[tx][ty]) -D[x][y] = max (D[x][y], D[tx][ty] +1); the } +D[x][y] = max (1, D[x][y]); A } theAns =Max (ans, d[x][y]); + } - return; $ } $ intMain () - { -scanf"%d%d", &row, &col); theLen =0; - for(inti =0; i < row; i++)Wuyi { the for(intj =0; J < Col; J + +) - { Wuscanf"%d", &map[i][j]); -node[len].x =i; AboutNODE[LEN].Y =J; $Node[len++].value =Map[i][j]; - } - } -Sort (node, node + len);//sort the points by-ascending- A DP (); +printf"%d\n", ans); the return 0; -}
ACM/ICPC's classic (poj1088-ski)