随笔分类 -  ACM模板

普通母函数
摘要:struct node//用于存储每个元素的大小与数量 { int value;//大小 int num;//数量 }lottery[100];void Generating(int n, int sum)//母函数过程,n表示元素的个数,sum表示和的最大值 { int c1[1000] = {1}; int c2[1000] = {0}; int i, j, k; for(i = 0; i < n; i++) { for(j = 0; j <= sum; j++) { for(k = 0; k+j<sum&&k<=lottery[i].num*lot 阅读全文

posted @ 2012-05-19 15:44 windmissing 阅读(121) 评论(0) 推荐(0)

用指针传递的字典树
摘要:#include <string> using namespace std; #define NUM 26 #define TYPE 'A' class dictree { public: dictree *child[NUM]; string *value;//节点所存的数据,根据题目而使用不同的类型或数据 dictree(){memset(child,0,sizeof(child));value=NULL;} ~dictree(); bool insert(string s, string s2); string search(string s); }; //把 阅读全文

posted @ 2012-05-18 21:34 windmissing 阅读(137) 评论(0) 推荐(0)

带权的二分匹配
摘要:#include <queue> #include <algorithm> /*********************************************************/ //这些都是KM模板 const int N = 305;//二分图中每一个子图的点的最大数 const int INF = 1<<28;//正无穷 bool xckd[N], yckd[N];//在一次DFS中,Xi与Yi是否在交错树上 int n;//点的个案 int edge[N][N];//二维权值信息用矩阵来存储 int xmate[N], ymate[N 阅读全文

posted @ 2012-05-18 20:08 windmissing 阅读(169) 评论(0) 推荐(0)

多源最短路径 Floyd
摘要:/* Floyd.h 时间复杂库:O(N^3) 用途: 1.判断中否联通 s[a][b] != inf -> 联通 s[a][b] == inf -> 不联通 2.两点间最短路径长度 s[a][b] != inf -> 最短路径长度 = s[a][b] s[a][b] == inf -> 不联通 3.两点间的最短路径的跳数 初始化时所有路径长度设为单位长度 s[a][b] != inf -> 跳数 = s[a][b] s[a][b] == inf -> 不联通 */ #include <iostream> using namespace std; 阅读全文

posted @ 2011-12-31 14:41 windmissing 阅读(219) 评论(0) 推荐(0)

搜索
摘要:HDU1254 推箱子 BFS+优先队列HDU2433 Travel BFS求最短路径树+优化HDU1401 Solitaire 双向搜索 阅读全文

posted @ 2011-12-31 13:41 windmissing 阅读(121) 评论(0) 推荐(0)

数论-Special Numbers
摘要:1.Fibonacci Number0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377, 610 …Formula:2.Lucas Number1, 3, 4, 7, 11, 18, 29, 47, 76, 123...Formula:3.Catalan Number1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786,208012…Formula:Application:1) 将 n + 2 边形沿弦切割成 n个三角形的不同切割数2) n + 1个数相乘, 给每两个元素加上括号的不同方法 阅读全文

posted @ 2011-12-31 13:04 windmissing 阅读(221) 评论(0) 推荐(0)

并查集
摘要:/* UnionFindSet.h 并查集,非递归方法,含路径压缩,数组从0开始 合并时,前者合并入后者,不区分大小 */ #include <iostream> using namespace std; #define MAXN 30005 class UFS { public: int n; int father[MAXN+1];//集合根结点 int rank[MAXN+1]; //集合中点的个数 int depth[MAXN+1]; //每个结点改变一次所属的集合,增加一些值 public: UFS(int size = MAXN); vo... 阅读全文

posted @ 2011-12-30 15:51 windmissing 阅读(147) 评论(0) 推荐(0)

树状数组
摘要:/* TreeArray.h 树状数组,一维和二维都有。数组必须从1开始 问题: 已知数组a[],元素个数为n,现在更改a中的元素,要求得新的a数组中i到j区间内的和 解决方法: 从图中不难发现,c[k]存储的实际上是从k开始向前数k的二进制表示中右边第一个1所代表的数字 个元素的和(这么说可能有点拗口,令lowbit为k的二进制表示中右边第一个1所代表的数字,然后 c[k]里存的就是从a[k]开始向前数lowbit个元素之和) C1 = A1 C2 = A1 + A2 C3 = A3 C4 = A1 + A2 + A3 + A4 C5 = A5 C6 = A5 + A6 C7 = A7 .. 阅读全文

posted @ 2011-12-30 13:45 windmissing 阅读(113) 评论(0) 推荐(0)