国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Free DIY Tour

2019-11-11 01:12:50
字體:
來源:轉載
供稿:網友

PRoblem Description

Weiwei is a software engineer of ShiningSoft. He has just Excellently fulfilled a software project with his fellow workers. His boss is so satisfied with their job that he decide to provide them a free tour around the world. It’s a good chance to relax themselves. To most of them, it’s the first time to go abroad so they decide to make a collective tour.

The tour company shows them a new kind of tour circuit - DIY circuit. Each circuit contains some cities which can be selected by tourists themselves. According to the company’s statistic, each city has its own interesting point. For instance, Paris has its interesting point of 90, New York has its interesting point of 70, ect. Not any two cities in the world have straight flight so the tour company provide a map to tell its tourists whether they can got a straight flight between any two cities on the map. In order to fly back, the company has made it impossible to make a circle-flight on the half way, using the cities on the map. That is, they marked each city on the map with one number, a city with higher number has no straight flight to a city with lower number.

Note: Weiwei always starts from Hangzhou(in this problem, we assume Hangzhou is always the first city and also the last city, so we mark Hangzhou both 1 and N+1), and its interesting point is always 0.

Now as the leader of the team, Weiwei wants to make a tour as interesting as possible. If you were Weiwei, how did you DIY it? Input The input will contain several cases. The first line is an integer T which suggests the number of cases. Then T cases follows. Each case will begin with an integer N(2 ≤ N ≤ 100) which is the number of cities on the map. Then N integers follows, representing the interesting point list of the cities. And then it is an integer M followed by M pairs of integers [Ai, Bi] (1 ≤ i ≤ M). Each pair of [Ai, Bi] indicates that a straight flight is available from City Ai to City Bi. Output For each case, your task is to output the maximal summation of interesting points Weiwei and his fellow workers can get through optimal DIYing and the optimal circuit. The format is as the sample. You may assume that there is only one optimal circuit.

Output a blank line between two cases.

這道題蠻尷尬的,開始我記錄的路徑是從前往后的不是很好,會出現某種情況的死循環。 我到現在還沒找出來問題,只能從后往前了。 代碼如下

#include <iostream>#include <vector>using namespace std;int main(){ int test_case; cin>>test_case; int count_case=test_case; while(test_case--){ int city_num; cin>>city_num; vector<int>city_points(city_num+5,0); for(int i=0;i<city_num;++i) cin>>city_points[i+1]; vector<int>point_sum(city_points); vector<int>road(city_num+5,1); int roads; cin>>roads; for(int i=0;i<roads;++i){ int start_city,end_city; cin>>start_city>>end_city; if( point_sum[start_city] + city_points[end_city] > point_sum[end_city]){ point_sum[end_city] = point_sum[start_city] + city_points[end_city]; road [end_city]=start_city; } } int start = city_num+1; vector<int>answer; while(start!=1){ answer.push_back(road[start]); start=road[start]; } cout<<"CASE "<<count_case-test_case<<'#'<<endl; cout<<"points : "<<point_sum[city_num+1]<<endl; cout<<"circuit : "; for(auto it = answer.rbegin();it!=answer.rend();it++) cout<<*it<<"->"; cout<<'1'<<endl; if(test_case!=0) cout<<endl; }}
上一篇:快速排序

下一篇:數組

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淮北市| 瑞安市| 临安市| 吴旗县| 临泽县| 准格尔旗| 图木舒克市| 温泉县| 汉沽区| 棋牌| 孟村| 五华县| 福建省| 武山县| 囊谦县| 庆元县| 寿阳县| 濮阳市| 甘孜| 锡林郭勒盟| 亚东县| 阿拉善盟| 衡阳市| 息烽县| 北流市| 屏山县| 彭州市| 德保县| 溧阳市| 晋州市| 新邵县| 张家川| 桑日县| 固镇县| 靖西县| 普兰县| 凤凰县| 裕民县| 大竹县| 林周县| 南昌市|