题目大意:

传送门

题解:

很容易建模,把每一个工作人员拆成两个点,由第一个点向第二个点连S+1条边即可。

这水题没什么难度,主要是longlong卡的丧心病狂。。。

代码

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2550;
const ll maxv = maxn * 10;
const ll inf = 1000000000000;
ll dist[maxv], inq[maxv], pree[maxv], fl[maxv];
struct edge {
ll from;
ll to;
ll cap;
ll cost;
};
vector<edge> edges;
vector<ll> G[maxv];
ll n, m, a[maxn][maxn], c[maxn], v;
void add_edge(ll from, ll to, ll cap, ll cost) {
edges.push_back((edge){from, to, cap, cost});
edges.push_back((edge){to, from, 0, -cost});
ll m = edges.size();
G[from].push_back(m - 2);
G[to].push_back(m - 1);
}
bool spfa(ll s, ll t, ll &cost) {
for (int i = 0; i < v; i++)
dist[i] = inf;
memset(inq, 0, sizeof(inq));
memset(pree, 0, sizeof(pree));
memset(fl, 0, sizeof(fl));
queue<ll> q;
fl[s] = inf;
dist[s] = 0, inq[s] = 1;
q.push(s);
while (!q.empty()) {
ll u = q.front();
q.pop();
inq[u] = 0;
for (int i = 0; i < G[u].size(); i++) {
edge &e = edges[G[u][i]];
if (e.cap > 0 && dist[e.to] > dist[u] + e.cost) {
dist[e.to] = dist[u] + e.cost;
pree[e.to] = G[u][i];
fl[e.to] = min(fl[u], e.cap);
if (!inq[e.to]) {
q.push(e.to);
inq[e.to] = 1;
}
}
}
}
if (dist[t] >= inf)
return false;
ll flow = fl[t];
cost += flow * dist[t];
ll u = t;
while (!u == s) {
edges[pree[u]].cap -= flow;
edges[pree[u] ^ 1].cap += flow;
u = edges[pree[u]].from;
}
return true;
}
ll mcmf(int s, int t) {
ll cost = 0;
while (spfa(s, t, cost))
;
return cost;
}
void solve() {
// 1-m:员工
// m+1~m+n 产品
// m+n+1~m+n+m 拆点后的员工
scanf("%lld %lld", &m, &n);
ll s = 0, t = n + m + m + 1;
v = t + 1; for (int i = 1; i <= n; i++) {
scanf("%lld", &c[i]);
add_edge(m + i, t, c[i], 0);
}
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++) {
int x;
scanf("%d", &x);
if (x)
add_edge(i, j + m, inf, 0);
}
for (int i = 1; i <= m; i++) {
add_edge(s, n + m + i, inf, 0);
ll s;
scanf("%lld", &s);
ll T[maxn];
T[0] = 0;
for (int j = 1; j <= s; j++)
scanf("%lld", &T[j]);
for (int j = 1; j <= s; j++) {
ll y;
scanf("%lld", &y);
add_edge(n + m + i, i, T[j] - T[j - 1], y);
}
scanf("%lld", &s);
add_edge(n + m + i, i, inf, s);
}
ll ans = mcmf(s, t);
printf("%lld\n", ans);
}
int main() {
// freopen("input", "r", stdin);
solve();
}

[bzoj2245][SDOI2011]工作安排——费用流的更多相关文章

  1. BZOJ 2245: [SDOI2011]工作安排( 费用流 )

    费用流模板题..限制一下不同愤怒值的工作数就可以了. ------------------------------------------------------------------------- ...

  2. 【bzoj2245】[SDOI2011]工作安排 费用流

    题目描述 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产品必须完整地由 ...

  3. P2488 [SDOI2011]工作安排 费用流

    \(\color{#0066ff}{ 题目描述 }\) 你的任务是制定出一个产品的分配方案,使得订单条件被满足,并且所有员工的愤怒值之和最小.由于我们并不想使用Special Judge,也为了使选手 ...

  4. [bzoj2245][SDOI2011]工作安排(费用流)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2245 分析: 要注意到题目下面说的w是单增的 明显的费用流: 弄个源点S,汇点T S连 ...

  5. bzoj2245: [SDOI2011]工作安排

    费用流. 这道题的模型比较明显,拆点也是很容易看出来的. #include<cstdio> #include<algorithm> #include<cstring> ...

  6. BZOJ 2245 SDOI 2011 工作安排 费用流

    题目大意:有一些商品须要被制造.有一些员工.每个员工会做一些物品,然而这些员工做物品越多,他们的愤慨值越大,这满足一个分段函数.给出哪些员工能够做哪些东西,给出这些分段函数,求最小的愤慨值以满足须要被 ...

  7. BZOJ2245 [SDOI2011]工作安排 【费用流】

    题目 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产品必须完整地由一名 ...

  8. 【BZOJ2245】[SDOI2011]工作安排(费用流)

    [BZOJ2245][SDOI2011]工作安排(费用流) 题面 BZOJ 洛谷 题解 裸的费用流吧. 不需要拆点,只需要连边就好了,保证了\(W_j<W_{j+1}\). #include&l ...

  9. 【BZOJ2245】[SDOI2011]工作安排 拆边费用流

    [BZOJ2245][SDOI2011]工作安排 Description 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被 ...

随机推荐

  1. 安装python虚拟运行环境,linux下轻松切换python2和python3

    一.查询系统采用的python版本 $ python --version Python 3.7.3 系统采用的python版本为3.7.3 以下查询py3和py2的目录: $ which python ...

  2. win10鼠标右键菜单在左边,怎么改回右边

    键盘上按WIN+R打开运行窗口,输入shell:::{80F3F1D5-FECA-45F3-BC32-752C152E456E}按回车键

  3. The Extinction of Some Languages【一些语言的消失】

    The Extinction of Some Languages Languages have been coming and going for thousands of years, 语言的产生和 ...

  4. Linux下添加桌面快捷方式

    这里用Ubuntu下BurpSuite举例 sudo vim /home/user/Desktop/burpsuite.desktop //burpsuite随意起名,系统会系动创建文件 文件写入 # ...

  5. 6,MongoDB 之 Array Object 的特殊操作

    相比关系型数据库, Array [1,2,3,4,5] 和 Object { 'name':'DragonFire' } 是MongoDB 比较特殊的类型了 特殊在哪里呢?在他们的操作上又有什么需要注 ...

  6. SpringMVC + MyBatis简单示例

    该项目基于Maven开发,该项目中包含了MyBatis自动创建表的功能,具体实现查阅MyBatis---自动创建表 源码下载 配置 maven支持pom.xml <project xmlns=& ...

  7. spring里面的context:component-scan

    原文:http://jinnianshilongnian.iteye.com/blog/1762632 component-scan的作用的自动扫描,把扫描到加了注解Java文件都注册成bean &l ...

  8. 《Cracking the Coding Interview》——第18章:难题——题目8

    2014-04-29 03:10 题目:给定一个长字符串S和一个词典T,进行多模式匹配,统计S中T单词出现的总个数. 解法:这是要考察面试者能不能写个AC自动机吗?对面试题来说太难了吧?我不会,所以只 ...

  9. .Net导出Word和Excel

    using System; using System.Collections.Generic; using System.Linq; using System.Web; public class Ex ...

  10. 发布“豪情”设计的新博客皮肤-darkgreentrip

    豪情 (http://www.cnblogs.com/jikey/)是一名在上海的前端开发人员,长期驻扎在园子里.他为大家设计了一款新的博客皮肤——darkgreentrip. 以下是该博客皮肤的介绍 ...