博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WuKong 最短路&&记忆化搜索
阅读量:7211 次
发布时间:2019-06-29

本文共 2750 字,大约阅读时间需要 9 分钟。

Problem Description
Liyuan wanted to rewrite the famous book “Journey to the West” (“Xi You Ji” in Chinese pinyin). In the original book, the Monkey King Sun Wukong was trapped by the Buddha for 500 years, then he was rescued by Tang Monk, and began his journey to the west. Liyuan thought it is too brutal for the monkey, so he changed the story:
One day, Wukong left his home - Mountain of Flower and Fruit, to the Dragon   King’s party, at the same time, Tang Monk left Baima Temple to the Lingyin Temple to deliver a lecture. They are both busy, so they will choose the shortest path. However, there may be several different shortest paths between two places. Now the Buddha wants them to encounter on the road. To increase the possibility of their meeting, the Buddha wants to arrange the two routes to make their common places as many as possible. Of course, the two routines should still be the shortest paths.
Unfortunately, the Buddha is not good at algorithm, so he ask you for help.
 

 

Input
There are several test cases in the input. The first line of each case contains the number of places N (1 <= N <= 300) and the number of roads M (1 <= M <= N*N), separated by a space. Then M lines follow, each of which contains three integers a b c, indicating there is a road between place a and b, whose length is c. Please note the roads are undirected. The last line contains four integers A B C D, separated by spaces, indicating the start and end points of Wukong, and the start and end points of Tang Monk respectively. 
The input are ended with N=M=0, which should not be processed.
 

 

Output
Output one line for each case, indicating the maximum common points of the two shortest paths.
 

 

Sample Input
6 6
1 2 1
2 3 1
3 4 1
4 5 1
1 5 2
4 6 3
1 6 2 4
0 0
 

 

Sample Output
3
***************************************************************************************************************************重点记忆化搜索
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1 #include
2 #include
3 #include
4 #include
5 #include
6 #define inf 0x3fffffff 7 using namespace std; 8 int map[330][330]; 9 int dis1[330],dis2[330]; 10 int dp[330][330]; 11 bool vis[330]; 12 int n; 13 void dijstra(int u,int dist[])//求单源最短路径 14 { 15 memset(vis,false,sizeof(vis)); 16 int mins,i,j,v; 17 for (i=1;i<=n;i++) 18 dist[i]=map[u][i]; 19 dist[u]=0; 20 vis[u]=true; 21 while(1) 22 { 23 mins=inf; 24 for (j=1; j<=n;j++) 25 if (!vis[j]&&dist[j]
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3430134.html

你可能感兴趣的文章
使用.NET Framework的配置文件app.config
查看>>
C++11 并发指南------std::thread 详解
查看>>
windows下编译chromium浏览器的15个流程整理
查看>>
p2p穿透技术
查看>>
Coding 初级教程(二)——上传已有项目
查看>>
Esper epl语句实验
查看>>
【TensorFlow】CNN
查看>>
redis cli命令
查看>>
网上开店进货渠道大参考
查看>>
图灵成立七周年——经典回顾
查看>>
我曾经七次鄙视自己的灵魂 卡里.纪伯伦
查看>>
Oracle 默认表空间(default permanent tablespace) 说明
查看>>
Dapper的语法应用
查看>>
Effective C++ 条款44
查看>>
MODBUS-RTU通讯协议简介
查看>>
在.net中序列化读写xml方法的总结(转载)
查看>>
百度贴吧高考作文强贴
查看>>
Leetcode: Design Hit Counter
查看>>
FrameBuffer编程二(简单的程序上)
查看>>
一种避免 iOS 内存碎片的方法
查看>>