ACM/ICPC's classic (poj1088-ski)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.