hdu 2833(Floyd + dp)
WuKong
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.
The input are ended with N=M=0, which should not be processed.
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;const int maxn = 305;
const int inf = 0x3f3f3f3f;
int n,m,dp[maxn][maxn],map[maxn][maxn];void floyd()
{for(int k = 1; k <= n; k++)for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++){if(map[i][j] > map[i][k] + map[k][j]){map[i][j] = map[i][k] + map[k][j];dp[i][j] = dp[i][k] + dp[k][j] - 1;}else if(map[i][j] == map[i][k] + map[k][j] && dp[i][j] < dp[i][k] + dp[k][j])dp[i][j] = dp[i][k] + dp[k][j] - 1;}
}int solve(int s1,int e1,int s2,int e2)
{int res = 0;for(int i = 1; i <= n; i++)for(int j = 1; j <= n; j++)if(map[s1][i] + map[i][j] + map[j][e1] == map[s1][e1] && map[s2][i] + map[i][j] + map[j][e2] == map[s2][e2])res = max(res,dp[i][j]);return res;
}int main()
{int u,v,w,s1,e1,s2,e2;while(scanf("%d%d",&n,&m),m+n){for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++){map[i][j] = inf;dp[i][j] = 2;}dp[i][i] = 1;map[i][i] = 0;}for(int i = 1; i <= m; i++){scanf("%d%d%d",&u,&v,&w);map[u][v] = map[v][u] = min(map[u][v],w);}floyd();scanf("%d%d%d%d",&s1,&e1,&s2,&e2);printf("%d\n",solve(s1,e1,s2,e2));}return 0;
}
hdu 2833(Floyd + dp)相关推荐
- hdu 六度分离 floyd
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1869 题意分析:比较简单的最短路算法,最后只需判断最远两点距离是否大于7即可. /*六度分离Time ...
- hdu 1520 树形dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1520 #include<cstdio> #include<cstring> # ...
- hdu2833 Floyd + dp
题意: 给你一个无向图,给你两组起点和终点,问你这两组起点和终点的最短路上最多有多少个交点... 思路: 开一个数组dp[i][j]记录最短路上i,j之间的点有多少个,这个数组是根 ...
- hdu 4035 可能性DP 成都网络游戏
http://acm.hdu.edu.cn/showproblem.php?pid=4035 获得: 1.首先推断是不是树.事实上,所有的感觉身影,既看边数==算-1是不成立 2.有时候,我告诉孩子来 ...
- HDU 2836 (离散化DP+区间优化)
Reference:http://www.cnblogs.com/wuyiqi/archive/2012/03/28/2420916.html 题目链接: http://acm.hdu.edu.cn/ ...
- hdu 5568(dp+大数模拟)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5568 官方题解: #include <cstdio> #include <cstri ...
- hdu 5464(简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5464 解题思路: 由于p很小,而ai很大,所以先把ai%p,由于ai可能有负数,所以ai=(ai%p+ ...
- hdu 5433(bfs+dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5433 解题思路: dp[i][j][k]表示在(x,y)点,毅力为k时的最小体力.由于每个点可能会走多 ...
- HDU 2833 WuKong
传送门 求两条最短路最多重叠的点数. 给一个无向图,再给两对起点终点,每一对起点终点之间都可能有多条最短的路,设s1和t1的最短路是r1,s2和t2的最短路是r2,求r1和r2最多能相互重叠多少个点. ...
最新文章
- vim 忽略大小写查找
- 小米redmi_99.9元!Redmi首款智能手环评测:能“打赢”小米手环5吗?
- 核心动画与UIView的区别
- php 去掉nbsp,php 正则去掉pnbsp;/p 空格 nbsp;
- 第四十五期:万亿级日访问量下,Redis在微博的9年优化历程
- 论文浅尝 | 基于迭代的概率规则约束的知识图谱分布式表示
- linux mysql 主从数据库_【Linux】【MySQL】MySQL主从数据库
- java org.jsoup does not exist_java使用Jsoup连接网站超时的解决方法
- 解决CentOS 6 字体变成方框的方法
- 堆积如山的Java面试简历,如何脱颖而出?写简历前你先要做这些
- mac matlab安装libsvm
- matlab ocx控件,matlabr.ocx控件下载
- MATLAB Cholesky分解
- Vbs脚本编程简明教程
- 【一起学习输入法】华宇拼音输入法开源版本解析(5)
- php制作600行表格,表格排版的基本操作
- 如何为NFT熊市做准备
- c语言编写fac函数 计算阶乘,编写一个计算阶乘的函数fac
- 企业文件加密软件如何做到根源防止泄密?全面专业的数据防泄密方案怎么选
- 第二篇 自制系统内核
热门文章
- 致客户的一封信:关于产品生命周期管理与高可用版本的提供
- 反馈速度小于 200ms!“弹窗”功能让你极速触达用户内心
- Django开发—如何重置migration
- 简便的chrome插件安装
- H盘由于IO设备错误,无法运行此项请求要怎样找到资料
- 探讨.NET Core数据进行3DES加密和解密问题
- 通过随机数生成兑换码和概率生成随机数
- HTML+CSS实例——漂亮的查询部件(一)
- 判断远程图片是否存在的JavaScript代码
- how to add the language things at the idiscover