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

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

Free DIY Tour

2019-11-11 00:47:25
字體:
來源:轉載
供稿:網友

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; }}
上一篇:遞歸之算24

下一篇:字符串

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 玉溪市| 塘沽区| 临沧市| 广饶县| 渭源县| 德保县| 二连浩特市| 开封市| 平安县| 齐齐哈尔市| 浦城县| 通许县| 乐平市| 长垣县| 广东省| 马尔康县| 阳原县| 阜宁县| 滦南县| 八宿县| 鄢陵县| 密云县| 昌都县| 翁牛特旗| 郁南县| 南充市| 文山县| 资阳市| 错那县| 万州区| 南召县| 启东市| 阿荣旗| 毕节市| 武陟县| 巫溪县| 马边| 马边| 昌吉市| 原阳县| 昆山市|