首页 > 科技
CS 1501代做、代写Python/Java程序设计
Support for Assignment 4
CS 1501
Sherif KhattabGeneral Hints
• You can get the number of vertices using ag.getAirports().size(), whereby
ag is an AirlineGraph object
• Iterate over airports using for(String airport: ag.getAirports()){ … }
• You can get a unique integer for each airport in the graph using the
ag.getAirportNo() method
• You can retrieve the set of neighbors of an airport using
ag.adj(airportName)
• To iterate over the set of neighbors: for(Route r: ag.adj(airportName)){ … }
• You can retrieve the name of a neighboring airport using r.destination
• You may use HashSet to instantiate Set objectsfewestStops
• Use BFS
• check the pseudo-code in lecture notes
• Shortest path Source -> transit -> destination can be found by
• shortest path source transit
• shortest path transit destination
• concatenate the two shortest paths
• Be careful not to add transit twice to the concatenated pathConnected Components
• Use BFS
• You can find the pseudo-code in the lecture notesallTrips
• Use backtracking and pruning
• Define a recursive helper method: solve(current decision, current solution)
• current decision current vertex (int or String) • current solution
• Set<ArrayList<Route>> of trips found so far
• current path: ArrayList<Route>
• total price so far of current path
• number of stops so far of current path
• destination, budget and max number of stops for comparison
• Inside the recursive helper method:
• if current vertex is the destination add current path to the solution set and return
• iterate over all possibilities (unmarked neighbors)
• check if you can add the neighbor to the current path (total price won’t exceed budget and total number of stops won’t exceed maximum stops)
• if so, mark neighbor, update current path, its price, and its number of stops.
• make a recursive call on the neighbor
• undo changes to current path, price, and number of stops and unmark neighbor
• mark start airport before calling solve the first timeallRoundTrips
• Use backtracking and pruning
• Define a recursive helper method: solve(current decision, current solution)
• current decision current vertex (int or String) • current solution
• Set<ArrayList<Route>> of trips found so far
• current path: ArrayList<Route>
• total price so far of current path
• number of stops so far of current path
• budget and max number of stops for comparison
• Inside the recursive helper method:
• if current vertex is the source and stops so far > 0 add current path to the solution set and return
• iterate over all possibilities (unmarked neighbors)
• check if you can add the neighbor to the current path (total price won’t exceed budget and total number of stops won’t exceed maximum stops)
• if so, mark neighbor, update current path, its price, and its number of stops.
• make a recursive call on the neighbor
• undo changes to current path, price, and number of stops and unmark neighbor
• Don’t mark start airport before calling solve the first time
请加QQ:99515681 邮箱:99515681@qq.com WX:codinghelp
- 搜索
-
- 01-15东莞市威勤户外用品有限公司:一站式高品质户外用品服务专家
- 01-15AI+电气时代纷至沓来,下一代数据中心HVDC如何发展?
- 01-15助听器选购指南:为什么爱可声助听器更值得入手?
- 01-152024国民消费“科技赋能”创新案例:Shokz韶音助推运动耳机音质升级
- 01-14暗揭湖南省康宸新材料有限公司客户对于全屋定制的环保性也是相当认可
- 01-14解谜武汉葳蕤繁祉百货有限公司时尚十元店秘诀就是它专业为出众而生
- 01-13Terra平台震撼来袭,引领WEB3新时代!
- 01-13中网智媒人工智能生态基金增值4.7倍,上市突破百倍指日可待!
- 01-11东莞赛铠机械:高品质混炼设备,助力中国智造崛起
- 01-11东莞市威勤户外用品有限公司:一站式高品质户外用品服务专家
- 标签列表