2018 杭电多校3 - M.Walking Plan
Little $$$Q$$$'s smart phone will record his walking route. Compared to stay healthy, Little $$$Q$$$ cares the statistics more. So he wants to minimize the total walking length of each day. Please write a program to help him find the best route.
In each test case, there are 2 integers $$$n,m(2≤n≤50,1≤m≤10000)$$$ in the first line, denoting the number of intersections and one way streets.
In the next m lines, each line contains 3 integers $$$u_i,v_i,w_i(1≤u_i,v_i≤n,u_i≠v_i,1≤w_i≤10000)$$$, denoting a one way street from the intersection $$$u_i$$$ to $$$v_i$$$, and the length of it is $$$w_i$$$.
Then in the next line, there is an integer $$$q(1≤q≤100000)$$$, denoting the number of days.
In the next $$$q$$$ lines, each line contains 3 integers $$$s_i,t_i,k_i(1≤s_i,t_i≤n,1≤k_i≤10000)$$$, describing the walking plan.
3 3
1 2 1
2 3 10
3 1 100
3
1 1 1
1 2 1
1 3 1
2 1
1 2 1
1
2 1 1
1
11
-1
$$$A_{ik}$$$ 可以理解为从$$$i$$$走到$$$k$$$的方案个数
$$$A_{kj}$$$ 可以理解为从$$$k$$$走到$$$j$$$的方案个数
那么最后求和的过程就是把$$$i$$$到$$$j$$$的所有方案求和了。以此类推,就能算出所有的方案个数。
回到这道题中,如果把矩阵乘法的细节修改一下,让$$$A_{ik}$$$ 记录$$$i$$$到$$$k$$$的最短距离,$$$A_{kj}$$$记录$$$k$$$到$$$j$$$的最短距离,计算$$${A^2}_{ij}$$$的过程变为取最小值,也就是$$$$$${A^2}_{ij}=min_{k}(A_{ik}+A_{kj})$$$$$$,就可以用类似矩阵乘法的思想,很快得到转移k步任意两点之间最短距离的表。
2018 杭电多校3 - M.Walking Plan的更多相关文章
- hdu6312 2018杭电多校第二场 1004 D Game 博弈
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 2018 杭电多校1 - Chiaki Sequence Revisited
题目链接 Problem Description Chiaki is interested in an infinite sequence $$$a_1,a_2,a_3,...,$$$ which i ...
- 2018 杭电多校2 - Naive Operations
题目链接 Problem Description In a galaxy far, far away, there are two integer sequence a and b of length ...
- 2018 杭电多校1 - Distinct Values
题目链接 Problem Description Chiaki has an array of n positive integers. You are told some facts about t ...
- 2018杭电多校第二场1003(DFS,欧拉回路)
#include<bits/stdc++.h>using namespace std;int n,m;int x,y;int num,cnt;int degree[100007],vis[ ...
- 2018杭电多校第六场1009(DFS,思维)
#include<bits/stdc++.h>using namespace std;int a[100010];char s[20];int zhiren[100010];vector& ...
- 2018杭电多校第五场1002(暴力DFS【数位】,剪枝)
//never use translation#include<bits/stdc++.h>using namespace std;int k;char a[20];//储存每个数的数值i ...
- 2018杭电多校第三场1003(状态压缩DP)
#include<bits/stdc++.h>using namespace std;const int mod =1e9+7;int dp[1<<10];int cnt[1& ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
随机推荐
- java的编码格式
几种常见的编码格式 为什么要编码 不知道大家有没有想过一个问题,那就是为什么要编码?我们能不能不编码?要回答这个问题必须要回到计算机是如何表示我们人类能够理解的符号的,这些符号也就是我们人类使用的语言 ...
- 20145202马超《网络对抗》Exp7 网络欺诈技术防范
本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法.具体有(1)简单应用SET工具建立冒名网站(2)ettercap DNS spoof(3)结合应用两种技术,用DNS spo ...
- program files与program files(x86)的区别
简单来说:Program Files (x86)存放了一些32位的系统文件.它和正常的Program Files以及Windows文件夹一样,都属于系统文件夹,请勿随意改动. 64位Windows中提 ...
- 北京Uber优步司机奖励政策(3月18日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Android Stadio配置了gralde的本地路径,但是windos 命令行还是会下载gradle
如下图: 已经在stadio 里面设置了gradle 的路径,但是在cmd 命令行里面不会去用这个路径. 解决方案:需要在环境变量里面设置一个gradle home GRADLE_USER_HOME ...
- Spring Boot中使用缓存
Spring Boot中使用缓存 随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决这一问题非常好的手段之一. 原始的使 ...
- 【JUC源码解析】AQS
简介 AQS,也即AbstractQueuedSynchronizer,抽象队列同步器,提供了一个框架,可以依赖它实现阻塞锁和相关同步器.有两种类型,独占式(Exclusive)和共享式(Share) ...
- Qt-QML-Charts-ChartView-编译错误-ASSERT: "!"No style available without QApplication!
昨天本来是回家想好好琢磨一下使用Chart来绘制曲线的,奈何在建立项目的时候也就卡住了,加上心情比较烦躁,也没有耐心寻找答案就草草了事.所以今天继续搞定这个. 上图是Qt 的编译错误截图 QML de ...
- ntp-redhat 同步时间配置
1. 选作一个机器作为ntp 服务端,例如 ip 为192.168.0.1 1)安装 ntp服务 yum install ntp 2) 修改ntp.conf 文件 vi /etc/ntp.conf 注 ...
- C 数据类型 常量 变量
一 数据类型 1. 什么是数据 生活中时时刻刻都在跟数据打交道 比如体重数据 血压数据 股价数据等 在我们使用计算机的过程中 会接触到各种各样的数据 有文档数据 图片数据 视频数据 还有聊QQ时产生的 ...