04 2014 档案
HDU 2485
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2485n个车站,m条边,两边之间费用为1,问最少摧毁多少车站,使得1-n无法在k时间内到达将2-(n-1)每个点拆成两个,并建立容量为1,费用为0的一条边,源点为1,汇点为2*n-2,这时求最小费用最大流,其中保证...
阅读全文
最小费用最大流
摘要:每边有一个权值,要求得到最大流并且使得权值和最小把EK算法中的bfs改成spfa,spfa需要注意的是进行松弛的边容量不能为0const int INF=0xfffffff ;struct node{ int s,t,cap,cost,nxt ;}e[200005] ;int sumflow ...
阅读全文
HDU 1533
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1533人和房子数量相同,每个人进房子,费用是人到房子的曼哈顿距离,求最小费用可用最小费用最大流求解,建立虚拟的源点和汇点即可#include #include #include #include using nam...
阅读全文
HDU 1402
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1402fft做O(nlog(n))大数乘法,kuangbin的模板#include #include #include #include #include using namespace std;const dou...
阅读全文
HDU 1498
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1498最小顶点覆盖,建立二分图求最大匹配#include #include #include using namespace std ;int M[105][105],k,n,match[505],vis[505]...
阅读全文
HDU 1281
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1281同行同列最多只能放一辆车,所以可以看做二分图。把x坐标和y坐标分别看做二分图的两边点集,把二分图的边看做放车,所以放最多的车就是求二分图的最大匹配。从头删边,如果删掉以后的最大匹配小于原最大匹配,该边就构成重...
阅读全文
HDU 4068
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4068暴力枚举两个全排列,犯了若干错误,以此为鉴#include #include #include #include using namespace std ;int n,f,m[10],vis[10],vis2...
阅读全文
HDU 1068
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1068应用匈牙利算法第三个扩展,求二分图的最大独立集,但由于路径是双向的,所以求出的最大匹配是实际最大匹配数*2,还要再除回去才行,单向路径就没有这个问题#include #include #include usi...
阅读全文
HDU 2444
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2444判断是否构成二分图,如果有则求最大匹配二分图判断用染色法,一个dfs就出来,具体看代码#include #include using namespace std ;int n,m ;struct node{ ...
阅读全文
匈牙利算法
摘要:二分图最大匹配邻接表:O(nm)struct node{ int s,t,nxt ; }e[1005] ;int k,m,n,head[505],cnt,match[505],vis[505] ;int find(int s){ for(int i=head[s] ;i!=-1 ;i=e...
阅读全文
HDU 3631
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3631只能走标记过的点,方法是标记哪个点就对哪个点做floyd#include #include #include using namespace std ;const int INF=0xfffffff ;int...
阅读全文
HDU 1198
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1198裸并查集,主要工作在根据题目给出关系构图#include #include #include using namespace std ;int idx[2505] ;int m,n ;char M[55][5...
阅读全文
HDU 4034
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4034给出最短路,问最少有几条边,floyd加一个变量记录该边是否取如果满足dis[i][k]+dis[k][j]==dis[i][j],那么i到j这条边就不取如果出现dis[i][k]+dis[k][j]#inc...
阅读全文
HDU 2807
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2807把矩阵相乘放在第二重循环,第三重循环只进行比较可以水过,优化的方法不懂主要用这题练习floyd的写法#include #include using namespace std ;const int INF=0...
阅读全文
斯特灵(Stirling)数
摘要:http://zh.wikipedia.org/wiki/%E6%96%AF%E7%89%B9%E7%81%B5%E6%95%B0第一类:n个元素分成k个非空循环排列(环)的方法总数递推式:s(n+1,k)=s(n,k-1)+n*s(n,k)解释:考虑第n+1个元素 1、单独形成循环排列,剩下的有s(n,k-1)种方法 2、和别的元素一起形成循环排列,n个元素形成循环排列的方法数是s(n,k),第n+1个可以放在第i个元 素左边,共有n种放法,一共是n*s(n,k)代码:memset(str1,0,sizeof(str1)) ;for(int i=1 ;i<=20 ;i++){ st..
阅读全文
|