摘要: 如题 阅读全文
posted @ 2013-08-15 09:29 认真的看我 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 二分图匹配的算法,二分图就是把图上的点分成两个互不相交的点集,而图中的边的端点只能分别属于这两个点集.二分图的匹配,就是婚配问题,左边的点集男性,右边的点集女性,然后相互配对(一夫一妻);最大匹配就是让好事最多.匈牙利算法可以实现这个东西.匈牙利算法怎么实现的这个东西.这个比较多.代码如下:#include #include #include #define MAX 100using namespace std;int n, m;int ans;bool vis[MAX];int use[MAX];bool c[MAX][MAX];void init(){ int x, y; ci... 阅读全文
posted @ 2013-07-29 20:21 认真的看我 阅读(222) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #define MAX 302using namespace std;int c[MAX][MAX];int pre[MAX];int visited[MAX];int n, m;bool Path(int src, int des){ queue q; for (int i = 0; i c[pre[i]][i]) { min = c[pre[i]][i]; } i = pre[i]; } i = d... 阅读全文
posted @ 2013-07-29 19:39 认真的看我 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 可以证明从树的任意一点出发,所能到达的最远距离一定是树的最大直径的端点。所以两次bfs(),一次任意一点出发,一次端点出发,便能找到最大直径。程序代码如下:(求树上两端点的最远距离)#include #include #define MAXN 10005#define INF 999999999using namespace std;struct Edge{ int v, w, next;}edge[MAXN];int head[MAXN], vis[MAXN], d[MAXN], q[MAXN], e, n;int init(){ e = 0; memset(head, -... 阅读全文
posted @ 2013-07-26 08:19 认真的看我 阅读(269) 评论(0) 推荐(0) 编辑
摘要: 邻接表是通过枚举所有的顶点,和顶点所能到达的所有的边来表示图的。所以有一个顶点域和边域。简单表述为struct Edge{ int v, w, next;}edge[MAXN];int e, head[MAXN];void init(){ e = 0; memset(head, -1, sizeof(head));}void add(int u, int v, int w){ edge[e].v = v; edge[e].w = w; edge[e].next = head[u]; head[u] = e++;} 阅读全文
posted @ 2013-07-26 07:59 认真的看我 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 从01背包到强银行再到放书。从分苹果到数的划分再到放格子。解决决策过程最忧化的方法。如果问题是由交叠子问题构成,我们就可以用动态规划的方法解决它。动态规划建议,与其对交叠子问题一次又一次的求解,不如把每个较小的问题只求解一次并把结果记录下来。这样就可以从记录中找到原始问题的解。关键是:描述问题,状态转移方程式,初始化,构建循环求解。 阅读全文
posted @ 2013-07-24 19:27 认真的看我 阅读(157) 评论(0) 推荐(0) 编辑
摘要: DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing e 阅读全文
posted @ 2013-05-14 22:18 认真的看我 阅读(109) 评论(0) 推荐(0) 编辑
摘要: DescriptionFarmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the same number line. Farmer John has two modes of transportation: walking and teleporting 阅读全文
posted @ 2013-05-12 16:31 认真的看我 阅读(123) 评论(0) 推荐(0) 编辑
摘要: DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence <i1, i2, ..., ik> of in 阅读全文
posted @ 2013-05-11 20:41 认真的看我 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Description在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?已经告诉你了,这是个DP的题目,你能AC吗?Input输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 100),表示数塔的高度,接下来用N行数字表示数塔,其中第i行有个i个整数,且所有的整数均在区间[0,99]内。Output对于每个测试实例,输出可能得到的最大和,每个实例的输出占一行。Sample Input1573 88 1 02 7 4 阅读全文
posted @ 2013-05-11 20:31 认真的看我 阅读(165) 评论(0) 推荐(0) 编辑