题意:给出 n ,k 表示接下来给你 n 段开区间,每段区间都有它的权值,问选出一些区间,使它的权值最大,并且在实轴上的每个点,不得超过 k次被覆盖. 思路:首先要理解建图思路,首先有一个基图,相邻点之间都有边,花费为0,容量为 k,然后再根据所给数据 u,v, w 建图,u,v,加一条容量为 1,花费为 - w的边,求最大费用最大流,只需将权值变为负数即可求出最短路,相反数即为最大值. 最小费用最大流,就是用SPFA寻找最短路(增广路容量是否大于流量,花费最短路),然后用最大流方法去计算最大流…
Minimum Cost POJ-2516 题意就是有n个商家,有m个供货商,然后有k种商品,题目求的是满足商家的最小花费供货方式. 对于每个种类的商品k,建立一个超级源点和一个超级汇点.每个商家和源点连线,容量为需要的商品数,每个供货商和汇点连线,容量为可以提供的商品数. 然后对于商家和供货商之间的连线就是,容量为INF,而费用就是题目提供的费用信息. #include<iostream> #include<cstdio> #include<algorithm> #i…
Going Home POJ-2195 这题使用的是最小费用流的模板. 建模的时候我的方法出现错误,导致出现WA,根据网上的建图方法没错. 这里的建图方法是每次到相邻点的最大容量为INF,而花费为1,因为花费等于距离.但是需要增加一个源点和一个汇点,然后将每个人和源点相连,每个房子和汇点相连,容量都为1,费用都为0. #include<iostream> #include<algorithm> #include<cstring> #include<queue>…
题意:http://acm.hdu.edu.cn/showproblem.php?pid=1533 相邻的容量为inf,费用为1,S到m容量为1,费用为0 ,H到T容量为1,费用为0. 建图跑-最小费用最大流-就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include <cstdio>//sprintf islower isupper #include <cstdlib>//malloc exit strc…
题目链接:http://poj.org/problem?id=2195 Time Limit: 1000MS Memory Limit: 65536K Description On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent…
Intervals Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5762   Accepted: 2288 Description You are given N weighted open intervals. The ith interval covers (ai, bi) and weighs wi. Your task is to pick some of the intervals to maximize t…
[题目链接] http://poj.org/problem?id=3680 [题目大意] 有N个带权重的区间,现在要从中选取一些区间, 要求任意点都不被超过K个区间所覆盖,请最大化总的区间权重. [题解] 我们将权重取负后进行建图,对于每个区间从首到末连边, 如果该路被增广则说明这个区间被选定,我们只要给定K的流量 最后求出最大流下的最小费用即可 [代码] #include <cstdio> #include <algorithm> #include <cstring>…
标准大白书式模板 #include<stdio.h> //大概这么多头文件昂 #include<string.h> #include<vector> #include<queue> #include<algorithm> using namespace std; +; //最大点数 const int INF=0x3f3f3f3f; struct edge{ //边:起点.终点.容量.流量.单位费用 int from,to,c,f,cost; e…
没有写单纯性的...应该不会有卡最小增广的出题人吧...(雾) struct MCMF{ struct tedge{int x,y,cap,flow,w,next;}adj[maxm];int ms,fch[maxn]; int n,m,d[maxn],p[maxn],a[maxn];bool inq[maxn]; void init(int n){ ; memset(fch,-,sizeof(fch)); return; } void addedge(int u,int v,int z,int…
稀疏图慢死了...但是稠密图效果还是很好的 struct MCMF{ struct tedge{int x,y,cap,w,next;}adj[maxm];int ms,fch[maxn]; int vis[maxn],d[maxn],ans,cost,S,T,n; void init(int n){ ;ans=cost=; memset(fch,-,sizeof(fch)); return; } inline void addedge(int u,int v,int cap,int w){ a…