如果不懂匈牙利算法,请点击:该趣味算法http://blog.csdn.net/dark_scope/article/details/8880547 模板: //DFS版本下的二分匹配算法 http://paste.ubuntu.net/16122581/ #include<cstdio> #include<iostream> #include<vector> #include<set> #include<map> #include<mat…
http://acm.hdu.edu.cn/showproblem.php?pid=5046 n城市建k机场使得,是每个城市最近机场的距离的最大值最小化 二分+DLX 模板题 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <vector>…
Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16748   Accepted: 6522 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled…
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonal…
POJ 1741. Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 34141   Accepted: 11420 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and…
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1242/ 这次的迷宫是有守卫的,杀死一个守卫需要花费1个单位的时间,所以以走的步数为深度,在每一层进行搜索,由于走一步的花费不一定是1,所以我们需要用优先队列寻找最优值.这个题目真是模板题. 代码如下: #include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsi…
题目: //多元广度优先搜索(bfs)模板题详细注释题解(c++)class Solution { int cnt; //新鲜橘子个数 int dis[10][10]; //距离 int dir_x[4]={0, 1, 0, -1}; int dir_y[4]={1, 0, -1, 0}; //表示四个方向 public: int orangesRotting(vector<vector<int>>& grid) { queue<pair<int,int>…
二分匹配的模板题,这里用网络流模板(见刘汝佳<算法竞赛入门经典·训练指南>P359 Dinic算法)做. 将男女生均看做网络上的节点,题中给出的每个"关系"看做一条起点为u节点,终点为v结点,容量为1的弧(因为每对"关系"只有匹配成功与失败两种情况,用1为容量即可表示).再取超级源汇s,t,由s向每个男生结点引容量为1的弧,每个女生结点向t引容量为1的弧(每个男生或是女生最多只能匹配成功一次,容量这样设置的话,一个结点与一个异性结点匹配成功后,它与所点的…
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> #include <string> #include <cmath> #include <que…
<题目链接> 题目大意: 给定一颗树,求出树的直径. 解题分析:树的直径模板题,以下程序分别用树形DP和两次BFS来求解. 树形DP: #include <cstdio> #include <algorithm> using namespace std; ; struct Edge{ int to,val,nxt; Edge(,,):to(_to),val(_val),nxt(_nxt){} }e[N<<]; int n,m,cnt,ans; int dp1…