HBC51248小幼稚买蛋糕,枚举,尺取法Sightseeing trip题解

arkfactor 算法基础篇 47 0
挑战自我,勇攀编程高峰!全网最全C++题库,助您成为编程达人。
In the town there are N crossing points numbered from 1 to N and M two-way roads numbered from 1 to M. Two crossing points can be connected by multiple roads, but no road connects a crossing point with itself. Each sightseeing route is a sequence of road numbers. should be different.The length of the sightseeing route is the sum of the lengths of all roads on the sightseeing route, i.e.. Your program has to find such a sightseeing route, the length of which is minimal, or to specify that it is not possible,because there is no sightseeing route in the town.

There is a travel agency in Adelton town on Zanzibar island. It has decided to offer its clients, besides many other attractions, sightseeing the town. To earn as much as possible from this attraction, the agency has accepted a shrewd decision: it is necessary to find the shortest route which begins and ends at the same place. Your task is to write a program which finds such a route. In the town there are N crossing points numbered from 1 to N and M two-way roads numbered from 1 to M. Two crossing points can be connected by multiple roads, but no road connects a crossing point with itself. Each sightseeing route is a sequence of road numbers y_1, ..., y_k y 1 ​ ,...,y k ​ , k>2. The road y_i (1 leq i leq k-1) y i ​ (1≤i≤k−1) connects crossing points x_i x i ​ and x_{i+1} x i+1 ​ , the road y_k y k ​ connects crossing points x_k x k ​ and x_1 x 1 ​ . All the numbers x_1,...,x_k x 1 ​ ,...,x k ​ should be different.The length of the sightseeing route is the sum of the lengths of all roads on the sightseeing route, i.e. L(y_1)+L(y_2)+...+L(y_k) L(y 1 ​ )+L(y 2 ​ )+...+L(y k ​ )where L(y_i) L(y i ​ ) is the length of the road y_i (1leq i leq k) y i ​ (1≤i≤k). Your program has to find such a sightseeing route, the length of which is minimal, or to specify that it is not possible,because there is no sightseeing route in the town.

HBC51248小幼稚买蛋糕,枚举,尺取法Sightseeing trip题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
全网最全C++题库,助您挑战自我,突破极限,成为编程领域的佼佼者!

标签: HBC51248小幼稚买蛋糕 枚举 尺取法Sightseeing trip题解