POJ1088 (ski)

Tried deep search results for each node of the TLE

Suddenly he found a very obvious DP

From the smallest node, update the node it around, if there is a high degree higher than its nodes, a high number of steps node + 1, because the update status of a node is certainly lower than the height it was acquired, thus updating four weeks than it low node has been determined that the maximum number of steps

// #include <the iostream> // POJ 1088 Ski
 // #include <cstdio> // depth test for each path search
 // #include <CString>
 // #include <algorithm>
 // the using namespace STD;
 // const MAXN 100 + 15 = int; // map
 // BOOL VIS [MAXN] [MAXN]; // determines whether each node visited
 // int the map [MAXN] [MAXN]; // map
 // int = 0 maxLen ; // longest path
 // int arrx [] = {. 1, -1,0,0};
 // int ARRY [] = {0,0,1, -1};
 // int R & lt, C; / / R & lt represents the number of rows, C represents the number of columns
 //DFS void (int X, Y int, int len) // from pos (x, y) coordinate to start the search, len is the current step number
 // {
 //      maxLen = max (len, maxLen);
 //      VIS [X] [Y] = to true; // graph already visited
 //      int newx, newy,; // new coordinates x, y location
 //      for (int I = 0; I =. 4;! I ++)
 //      {
 //          newx arrx = X + [I];
 //          newy, ARRY = Y + [I]; // new position
 //          IF (VIS [newx] [newy,])
 //              Continue;
 //          IF (newx <0 | | newx> = R & lt newy, || <|| 0 newy,> C =)
 //              Continue; // prevent cross-border
//         if(Map[newx][newy] < Map[x][y])
//             dfs(newx,newy,len+1);
//         vis[newx][newy] = false;//回溯
//     }
// }
// int main()
// {
//     while(cin>>R>>C)
//     {
//         for(int i=0;i!=R;++i)
//         {
//             for(int j=0;j!=C;++j)
//                 cin>>Map[i][j];//输入地图
//         }
//         for(int i=0;i!=R;++i)
//         {
//             for (int J = 0; J = C;! J ++)
 //              { // try from each point
 //                  memset (VIS, false, sizeof (VIS)); // reset the access map
 //                  the DFS (I, J,. 1);
 //              }
 //          }
 //          COUT maxLen << << endl;
 //      }
 // } 
/////////////// / movable gauge (dynamic planning) 
#include <the iostream> 
#include <cstdio> 
#include <Vector> 
#include <algorithm>
 the using  namespace STD; // classic the DP 
int R & lt, C; //R represents a row, C for column 
const  int MAXN = 100 + 15 ;
 int the Map [MAXN] [MAXN]; // map (stored value for each point) 
int CNT [MAXN] [MAXN]; 
typedef struct 
{ 
    int X, Y; // X representing lines, y for column 
    int H; // height 
} node; // each node represents a position 
Vector <node> V;
 BOOL CMP ( const node N1 &, const node & N2) 
{ 
    return n1.h < n2.h; 
} 
int arrx [] = { . 1 , - . 1, 0 , 0 };
 int ARRY [] = { 0 , 0 , . 1 , - . 1 };
 int main () // I for all the DP 
{
     the while (R & lt CIN >> >> C) 
    { 
        Node tmp; 
        for ( int I = 0 ; I = R & lt;! ++ I) 
        { 
            for ( int J = 0 ; J = C;! ++ J) 
            { 
                CNT [I] [J] = . 1 ; // initialization step number. 1 
                tmp .x =I; 
                tmp.y = J; 
                CIN >> tmp.h; 
                the Map [I] [J] = tmp.h; 
                v.push_back (tmp); 
            } 
        } 
        // in ascending order (H) 
        Sort (v.begin (), v.end (), CMP);
         for ( int I = 0 ; I = C * R & lt;! I ++) // for each node 
        {
             for ( int J = 0 ; J =! . 4 ; + + J) 
            { 
                int newx = V [I] .x + arrx [J];
                 intOF NEW = v [i] .e + arry [j];
                os (newx < 0 || newx> = R || OF NEW < 0 || OF NEW> = C)
                     Continue ; // 防止越界
                os (Map [newx] [OF NEW]> v [i] .h) 
                    they shall have [newx] [OF NEW] = max (they shall have [newx] [OF NEW], they shall have [v [i] .x] [v [i] .e] + 1 ); 
            } 
        } 
        Int maxlen = 0 ; 
        for ( int i = 0 ; to! = R; ++ i) 
        { 
            for ( int j = 0 ; j! = C; ++ j)
                maxlen = max(maxlen,cnt[i][j]);
        }
        cout<<maxlen<<endl;
    }
}

 

Guess you like

Origin www.cnblogs.com/newstartCY/p/11460856.html