摘要: 一、Bellman-Ford算法最优性原理它是最优性原理的直接应用,算法基于以下事实:l 如果最短路存在,则每个顶点最多经过一次,因此不超过n-1条边;l 长度为k的路由长度为k-1的路加一条边得到;l 由最优性原理,只需依次考虑长度为1,2,…,k-1的最短路。适用条件&范围l 单源最短路径(从源点s到其它所有顶点v); l 有向图&无向图(无向图可以看作(u,v),(v,u)同属于边集E的有向图); l 边权可正可负(如有负权回路输出错误提示); l 差分约束系统(需要首先构造约束图,构造不等式时>=表示求最小值, 作为最长路,<=表示求最大值, 作为最短路。& 阅读全文
posted @ 2011-04-30 06:40 L.. 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 裸的拓扑排序 图用邻接表表示方法是dfs#include<stdio.h>#include<string.h>const int MAXN = 1000;struct edge{ int u, v, next;}e[MAXN];int n;int first[MAXN], cnt;bool visit[MAXN], f;int sort[MAXN], top;void dfs(int s){ if(visit[s]) return; visit[s] = true; for(int x = first[s]; x != -1; x = e[x].next){ if(!v 阅读全文
posted @ 2011-04-30 06:34 L.. 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 留下代码有空写解题报告 蛋疼的题目#include<stdio.h>const int MAXN = 501;const int INF = 0x3f3f3f3f;int n, m;int map[MAXN][MAXN], dist[MAXN];bool used[MAXN];void dijkstra(){ for(int i = 1; i <= n; ++i){ dist[i] = map[1][i]; used[i] = false; } used[1] = true; dist[1] = 0; for(int i = 1; i < n; ++i){ int mi 阅读全文
posted @ 2011-04-30 05:39 L.. 阅读(299) 评论(0) 推荐(0) 编辑
摘要: where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types1/Σ(to,td)d(to,td)派生关系有向边,边权为两个串的不同字符的个数,要求的是找出一种用到所有串的派生关系,使得Q最小,(因为是1/Q),所以这题就是求最小生成树 最朴素的最小生成树AC#include<stdio.h>const 阅读全文
posted @ 2011-04-30 01:36 L.. 阅读(131) 评论(0) 推荐(0) 编辑