最大流:HDU-3572 ( Tas…
来源:互联网 发布:2016淘宝视频开店教程 编辑:程序博客网 时间:2024/06/15 19:41
#include
#include
#include
#include
#include
#define INF 0x7fffffff
using namespace std;
const int MAXN = 1020;
const int MAXM = MAXN*MAXN;
struct edge{ int to, c; int next;}edge[MAXM];
int size,head[MAXN];
void addEdge(int from, int to, int c)
{ edge[size].to = to; edge[size].c = c; edge[size].next = head[from];
head[from] = size++;
edge[size].to = from; edge[size].c = 0; edge[size].next = head[to];
head[to] = size++;
}
int n,m,ans,Max;int h[MAXN],gap[MAXN],cur[MAXN],pre[MAXN];
int SAP_GAP(int start,int end,int N)
{ int cur_flow,flow_ans=0,u,tmp,neck,i;
memset(h,0,sizeof(h)); memset(gap,0,sizeof(gap)); memset(pre,-1,sizeof(pre));
for (i=0;i<=N;i++) cur[i]=head[i];
gap[0]=N; u=start;
while(h[start]<</font>N)
{ if(u==end)
{ cur_flow=INF;
(i=start;i!=end;i=edge[cur[i]].to) for
{ if (cur_flow>edge[cur[i]].c){ neck=i; cur_flow=edge[cur[i]].c; } }
(i=start;i!=end;i=edge[cur[i]].to) for
{ tmp=cur[i]; edge[tmp].c-=cur_flow; edge[tmp^1].c+=cur_flow; }
+=cur_flow; u=neck; flow_ans
}
(i=cur[u];i!=-1;i=edge[i].next) for
if (edge[i].c&&h[u]==h[edge[i].to]+1)break ;
(i!=-1) if
{[u]=i; pre[edge[i].to]=u; u=edge[i].to; } cur
else
{[h[u]]--; if(gap[h[u]]==0) break; cur[u]=head[u]; gap
(tmp=N,i=head[u];i!=-1;i=edge[i].next) for
if (edge[i].c) tmp=min(tmp,h[edge[i].to]);
h[u]=tmp+1;
gap[h[u]]; ++
(u!=start) u=pre[u]; if
}
}
return flow_ans;
}
void init()
{
int pi, si, ei;
("%d%d", &n, &m); scanf
size = 0;ans = 0;Max = 0;
memset (head, -1, sizeof(head));
for (int i = 1; i <= n; i++)
{ ("%d%d%d", &pi, &si, &ei); scanf
+= pi; ans
(0, i, pi); addEdge
= max(Max, ei); Max
(int j = si; j <= ei; j++) for
{ (i, n + j, 1); } addEdge
}
for (int i = 1; i <= Max; i++) addEdge(n + i,n+Max+1, m);
}
int main()
{ //freopen("in.txt","r",stdin);
test; int ans_s; int
("%d", &test); scanf
(int i = 0; i <</font> test; i++) for
{
init();
ans_s =SAP_GAP(0,n+Max+1,n+Max+2);
if ( ans_s == ans) printf("Case %d: Yes\n\n", i+1);
else printf("Case %d: No\n\n", i+1);
}
0; return
}
0 0
- 最大流:HDU-3572 ( Tas…
- ZZULI_SummerPractice(3) HDU 1…
- HDU 1075 What Are You Talking …
- ACM: 二分图最大匹配 hdu 2063
- poj 2584 T-Shirt Gumbo(最大流 s…
- ACM: 最小费用最大流 图论题 poj 2…
- poj 2239 Selecting Courses (最大…
- hdu 2039 三角形 /…
- hdu 1303 doubles …
- hdu 1374 || poj22…
- hdu 2708 || poj21…
- hdu3572 最大流
- poj1149 最大流
- 图论: 最大流
- HDU 1423 Greatest Common Increas…
- hdu 1197 Specialized …
- hdu 1497 Simple Library Manageme…
- hdu 1798 Tell me the area …
- 最大流:SAP+GAP模版
- ubuntu 13.10 64bit装BeyondCompare
- 使用ALAssetsLibrary读取所有照片
- 退出、测试、判断及操作符
- 循环与结构化命令
- 最大流:HDU-3572 ( Tas…
- 最大流:HDU-4289(CONTROL)
- 最大流:HDU-4292(Food)
- pl/sql 中操作DML语句
- mySQL alter使用方法
- MySQL 外键
- mysql一些命令
- java技巧-连接数据库
- Java技巧-日期