Going Home Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5504    Accepted Submission(s): 2890 Problem Description On a grid map there are n little men and n houses. In each unit time, every l…
题目链接:https://vjudge.net/problem/POJ-2195 Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24015   Accepted: 12054 Description On a grid map there are n little men and n houses. In each unit time, every little man can move one u…
Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26212   Accepted: 13136 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4289 Description:On a grid map there are n little men and n houses. In each unit time, every little man can…
题意:给一个n*m的地图,'m'表示人,'H'表示房子,求所有人都回到房子所走的距离之和的最小值(距离为曼哈顿距离). 思路:比较明显的二分图最大权匹配模型,将每个人向房子连一条边,边权为曼哈顿距离的相反数(由于是求最小,所以先取反后求最大,最后再取反回来即可),然后用KM算法跑一遍然后取反就是答案.还可以用最小费用最大流做,方法是:从源点向每个人连一条边,容量为1,费用为0,从每个房子向汇点连一条边,容量为1,费用为0,从每个人向每个房子连一条边,容量为1,费用为曼哈顿距离的值,建好图后跑一遍…
网络流相关知识参考: http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html 出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6732762 大致题意: 给定一个N*M的地图,地图上有若干个man和house,且man与house的数量一致.man每移动一格需花费$1(即单位费用=单位距离),一间house只能入住一个man.现在要求所有的man都入住hou…
题目链接:http://poj.org/problem?id=2195 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:27150   Accepted: 13536 Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either…
最小费用最大流板子,没有压行.利用重标号让边权非负,用Dijkstra进行增广,在理论和实际上都比SPFA增广快得多.教程略去.转载请随意. #include <cstdio> #include <cstring> #include <algorithm> #include <functional> #include <queue> using namespace std; ; const int inf = 0x33333333; typede…
其实本来打算做最小费用最大流的题目前先来点模板题的,,,结果看到这道题二话不说(之前打太多了)敲了一个dinic,快写完了发现不对 我当时就这表情→   =_=你TM逗我 刚要删突然感觉dinic的模板中的bfs就相当于找每天边的权都为1的图上的最短路,稍稍改一下就能变成spfa,于是重新写了一下,但是函数名还是bfs... 然后又发现不对,最后要返回路径的,dfs也要改= =结果变成了非递归,但是函数名还是dfs... 于是一个看似是dinic,实则垃圾得不行的最小费用最大流就敲完了 然后调了…
将每个点拆分成原点A与伪点B,A->B有两条单向路(邻接表实现时需要建立一条反向的空边,并保证环路费用和为0),一条残留容量为1,费用为本身的负值(便于计算最短路),另一条残留容量+∞,费用为0(保证可以多次通过该点,但费用只计算一次). 另外伪点B与原点右侧与下方的点有一条单向路(邻接表实现需要建立反向空边),残留容量为+∞,费用为0.源点0到点1有一条单向路,残留容量为K(可以通过K次),最后一个点的伪点2*n*n与汇点2*n*n+1有一条单向边,残留容量为K,两条边的费用都为0. 构图成功…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern University.…