\(\color{#0066ff}{ 题目描述 }\)

有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成。 现在给出这些参数,求最大利润

\(\color{#0066ff}{输入格式}\)

第一行给出 N,M(1<=N<=1200,1<=M<=1200) 下面将有N组数据。

每组数据第一行给出完成这个任务能赚到的钱(其在[1,5000])及有多少道工序

接下来若干行每行两个数,分别描述完成工序所需要的机器编号及租用它的费用(其在[1,20000]) 最后M行,每行给出购买机器的费用(其在[1,20000])

\(\color{#0066ff}{输出格式}\)

最大利润

\(\color{#0066ff}{输入样例}\)

2 3
100 2
1 30
2 20
100 2
1 40
3 80
50
80
110

\(\color{#0066ff}{输出样例}\)

50

\(\color{#0066ff}{数据范围与提示}\)

none

\(\color{#0066ff}{ 题解 }\)

显然每个工作不是必须要选的,根据数据范围,显然是网络流

利润=总收益-成本,显然要最小割

目前有三个值,收益,租费,购买费

S到每个工作连收益的边

每个工作向需要机器连租费的边

每个机器向T连购买费的边

这样租金只会对当前工作有影响,而收益和购买费会对全局有影响

这样求出最小割,用总收益一减即可

#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int maxn = 1e5 + 10;
const int inf = 0x7fffffff;
struct node {
int to, dis;
node *nxt, *rev;
node(int to = 0, int dis = 0, node *nxt = NULL): to(to), dis(dis), nxt(nxt) { rev = NULL; }
void *operator new(size_t) {
static node *S = NULL, *T = NULL;
return (S == T) && (T = (S = new node[1024]) + 1024), S++;
}
};
node *head[maxn], *cur[maxn];
int dep[maxn], n, m, s, t;
void add(int from, int to, int dis) {
head[from] = new node(to, dis, head[from]);
}
void link(int from, int to, int dis) {
add(from, to, dis);
add(to, from, 0);
head[from]->rev = head[to];
head[to]->rev = head[from];
}
bool bfs() {
for(int i = s; i <= t; i++) dep[i] = 0, cur[i] = head[i];
std::queue<int> q;
q.push(s);
dep[s] = 1;
while(!q.empty()) {
int tp = q.front(); q.pop();
for(node *i = head[tp]; i; i = i->nxt)
if(!dep[i->to] && i->dis)
dep[i->to] = dep[tp] + 1, q.push(i->to);
}
return dep[t];
}
int dfs(int x, int change) {
if(x == t || !change) return change;
int flow = 0, ls;
for(node *i = cur[x]; i; i = i->nxt) {
cur[x] = i;
if(dep[i->to] == dep[x] + 1 && (ls = dfs(i->to, std::min(i->dis, change)))) {
change -= ls;
flow += ls;
i->dis -= ls;
i->rev->dis += ls;
if(!change) break;
}
}
return flow;
}
int dinic() {
int flow = 0;
while(bfs()) flow += dfs(s, inf);
return flow;
}
int main() {
int ans = 0;
n = in(), m = in();
s = 0, t = n + m + 1;
for(int i = 1; i <= n; i++) {
int r = in();
ans += r;
link(s, i, r);
for(int T = in(); T --> 0;) {
int id = in(), v = in();
link(i, n + id, v);
}
}
for(int i = 1; i <= m; i++) link(n + i, t, in());
printf("%d\n", ans - dinic());
return 0;
}

P4177 [CEOI2008]order 最小割的更多相关文章

  1. BZOJ 1391: [Ceoi2008]order [最小割]

    1391: [Ceoi2008]order Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1509  Solved: 460[Submit][Statu ...

  2. [CEOI2008]order --- 最小割

    [CEOI2008]order 题目描述: 有N个任务,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成. 现在给出这些参数, ...

  3. P4177 [CEOI2008]order(网络流)最大权闭合子图

    P4177 [CEOI2008]order 如果不能租机器,这就是最大权闭合子图的题: 给定每个点的$val$,并给出限制条件:如果取点$x$,那么必须取$y_1,y_2,y_3......$,满足$ ...

  4. 【BZOJ-1391】order 最小割 + 最大全闭合图

    1391: [Ceoi2008]order Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1334  Solved: 405[Submit][Statu ...

  5. P4177 [CEOI2008]order

    传送门 答案等于总工作价值减去最小失去的价值 考虑构建最小割模型 在 $S$割 的点表示选,在 $T$割 的点表示不选 对于机器(编号从 $n+1$ 到 $n+m$) $n+i$,连边 $(n+i,T ...

  6. P4177 [CEOI2008]order 网络流,最小割,最大权闭合子图

    题目链接 \(Click\) \(Here\) 如果没有租用机器就是一个裸的最大权闭合子图.现在有了租用机器应该怎么办呢? 单独拆点是不行的,因为会和直接买下的情况脱离关系,租借是和连边直接相关的,那 ...

  7. 洛谷$P4177\ [CEOI2008]\ order$ 网络流

    正解:网络流 解题报告: 传送门$QwQ$ 开始看感$jio$长得好像和太空飞行计划差不多的,,,然后仔细康康发现还有租操作,,, 按一般的套路碰到这样儿的一般就先按非特殊化的建图然后考虑怎么实现这个 ...

  8. bzoj 1391 [Ceoi2008]order(最小割)

    [题意] 有n个有偿工作选做,m个机器,完成一个工作需要若干个工序,完成每个工序需要一个机器,对于一个机器,在不同的工序有不同的租费,但买下来的费用只有一个.问最大获益. [思路] 对于工作和机器建点 ...

  9. 【bzoj1391】[Ceoi2008]order 网络流最小割

    原文地址:http://www.cnblogs.com/GXZlegend/p/6796937.html 题目描述 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序 ...

随机推荐

  1. Oracle 静默安装oracle client

    静默安装oracle clint比较简单,修改instantclient.crsp文件的几个位置即可 [root@localhost ~]# vi /etc/oralnstloc inventory_ ...

  2. 新手编译开发OpenWrt入门教程(自定义固件、ubuntu学习)

    转自:   http://www.znck007.com/forum.php?mod=viewthread&tid=21571 由于openwrt编译教程资料很多,不同的cpu芯片只需要选择对 ...

  3. ruby中nil?, empty? and blank?

    In Ruby, you check with nil? if an object is nil: article = nil article.nil? # => true empty? che ...

  4. Appium—python_ 安卓手机划屏幕操作

    开始的时候 不知道 python_unittest框架的命名规则,导致方法进不去,后来 改变方法名 能获取 # conding=utf- from appium import webdriver im ...

  5. Java 中的关键字和保留字

    关键字: Java 语言中已经事先定义好了的,有着特殊含义和用途 访问控制 类.方法和变量修饰符 程序控制 异常处理 包相关 基本类型 变量引用 public abstract break try i ...

  6. Profile配置

    Profile是Spring用来针对不同环境对不同的配置提供支持的,全局Profile配置使用application-{profile}.properties application.properti ...

  7. How to recover destroyed ZFS storage pools

    root@sol11ai:~# zpool status tank   pool: tank state: ONLINE   scan: resilvered 91K in 0h0m with 0 e ...

  8. myeclipse与eclipse的web项目部署区别

    一.myeclipse之web项目的部署(发布)流程 web项目的部署(发布)流程2008-01-18 14:35 在myeclipse下新建web工程abc.系统设置默认如下: 项目保存位置:wor ...

  9. oracle 基础 执行sql文件

    Oracle执行外部文件: c:>sqlplus user/pwd@db sql>@new.sql 执行多个sql文件: 1.把所有的文件都放在同一个目录下,然后在命令行里执行命令:    ...

  10. php中定义数组的方法

    1.PHP定义数组的格式 数组名=array(); 如:$aa=array();//这样就定义了一个数组, 之后给元素赋值: $aa[0]="9016"; $aa[1]=" ...