[原题](http://poj.org/problem?id=3068) 给一个有向带权图,求两条从0-N-1的路径,使它们没有公共点且边权和最小 . //是不是像传纸条啊- 是否可行只要判断最后最大流是不是2就可以了 #include<cstdio> #include<queue> #include<cstring> #define N 1010*1010 #define inf 0x3f3f3f3f using namespace std; int n,m,head…
[题目链接] http://poj.org/problem?id=3068 [题目大意] 给出一张图,要把两个物品从起点运到终点,他们不能运同一条路过 每条路都有一定的费用,求最小费用 [题解] 题目等价于求两条无交叉最短路,可用流量为2的费用流求解 [代码] #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; con…
"Shortest" pair of paths Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1407   Accepted: 627 Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There ar…
题意:有一个矩阵,某些格有人,某些格有房子,每个人可以上下左右移动,问给每个人进一个房子,所有人需要走的距离之和最小是多少. 貌似以前见过很多这样类似的题,都不会,现在知道是用KM算法做了 KM算法目前还没弄懂,先套模板做 Sample Input 2 2 .m H. 5 5 HH..m ..... ..... ..... mm..H 7 8 ...H.... ...H.... ...H.... mmmHmmmm ...H.... ...H.... ...H.... 0 0 Sample Out…
"Shortest" pair of paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1589 Accepted: 708 Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There are M…
POJ3068 "Shortest" pair of paths Description A chemical company has an unusual shortest path problem. There are N depots (vertices) where chemicals can be stored. There are M individual shipping methods (edges) connecting pairs of depots. Each i…
描述 Alice and Bob are walking in an ancient maze with a lot of caves and one-way passages connecting them. They want to go from cave 1 to cave n. All the passages are difficult to pass. Passages are too small for two people to walk through simultaneou…
http://poj.org/problem?id=2195 题意:有一个地图里面有N个人和N个家,每走一格的花费是1,问让这N个人分别到这N个家的最小花费是多少. 思路:通过这个题目学了最小费用最大流.最小费用最大流是保证在流量最大的情况下,使得费用最小. 建图是把S->人->家->T这些边弄上形成一个网络,边的容量是1(因为一个人只能和一个家匹配),边的费用是曼哈顿距离,反向边的费用是-cost. 算法的思想大概是通过SPFA找增广路径,并且找的时候费用是可以松弛的.当找到这样一条增…
这就是一道最小费用最大流问题 最大流就体现到每一个'm'都能找到一个'H',但是要在这个基础上面加一个费用,按照题意费用就是(横坐标之差的绝对值加上纵坐标之差的绝对值) 然后最小费用最大流模板就是再用最短路算法找最小费用路径.然后在找到这条路径上面的最大流..就这样一直找下去 代码: 1 //这是一个最小费用最大流问题 2 //最大费用最小流只要在添加边的时候换一下位置就好了 3 //求最大费用最大流只需要把费用换成相反数,用最小费用最大流求解即可 4 #include <cstdio> 5…
                                                        Kaka's Matrix Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9460   Accepted: 3844 Description On an N × N chessboard with a non-negative number in each grid, Kaka starts h…