题目:http://community.topcoder.com/stat c=problem_statement&pm=12468&rd=15493
题目的难点是要把题目转化成求解最短路径模型。参考一位大牛的话:
Make the pair: (hill, altitude) to represent a node.
you need to find the shortest path from
(0, any_altitude) to (n-1, any_altitude)
Next trick is to observe the altitudes that matter are the ones from vector A (altitudes).
Now a node is (hill, j) (you are at hill with Altitude A[j]). Run the your shortest path algorithm...
代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include