题面

题解

如果没有分段函数的限制的话就很好做了

但是我们发现分段函数的段很少,我们就可以将每一段拆开,

强制限制一定流量就可以了

代码

#include<cstdio>
#include<cstring>
#include<cctype>
#include<climits>
#include<algorithm>
#include<queue>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x)) inline int read()
{
int data = 0, w = 1; char ch = getchar();
while(ch != '-' && (!isdigit(ch))) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
} const int maxn(1010), maxm(500010);
struct edge { int next, to, cap, dis; } e[maxm];
int head[maxn], e_num = -1, n, S, T, m;
int pre[maxn], pre_e[maxn], vis[maxn];
long long cost, flow, dis[maxn], h[maxn];
int g[300][300], t[11], c[11]; inline void add_edge(int from, int to, int cap, int dis)
{
e[++e_num] = (edge) {head[from], to, cap, dis}; head[from] = e_num;
e[++e_num] = (edge) {head[to], from, 0, -dis}; head[to] = e_num;
} std::queue<int> q;
void MinCostMaxFlow()
{
std::fill(h + S, h + T + 1, 0);
cost = flow = 0; int f = 1000000007;
while(f)
{
std::fill(dis + S, dis + T + 1, LLONG_MAX >> 1); clear(vis, 0);
dis[S] = 0, q.push(S);
while(!q.empty())
{
int x = q.front(); q.pop();
for(RG int i = head[x]; ~i; i = e[i].next)
{
int to = e[i].to, ds = e[i].dis + dis[x] + h[x] - h[to];
if(e[i].cap > 0 && ds < dis[to])
{
dis[to] = ds, pre[to] = x, pre_e[to] = i;
if(!vis[to]) vis[to] = 1, q.push(to);
}
}
vis[x] = 0;
}
if(dis[T] == LLONG_MAX >> 1) return;
for(RG int i = S; i <= T; i++) h[i] += dis[i];
int cap = f;
for(RG int i = T; i ^ S; i = pre[i])
cap = std::min(cap, e[pre_e[i]].cap);
f -= cap, flow += cap, cost += cap * h[T];
for(RG int i = T; i ^ S; i = pre[i])
e[pre_e[i]].cap -= cap, e[pre_e[i] ^ 1].cap += cap;
}
} int main()
{
clear(head, -1); n = read(), m = read(); S = 0, T = n + m + 1;
for(RG int i = 1; i <= m; i++)
add_edge(i + n, n + m + 1, read(), 0);
for(RG int i = 1; i <= n; i++)
for(RG int j = 1; j <= m; j++)
g[i][j] = read();
for(RG int i = 1, x; i <= n; i++)
{
x = read();
for(RG int j = 1; j <= x; j++) t[j] = read();
for(RG int j = 1; j <= x + 1; j++) c[j] = read();
for(RG int j = 1; j <= x; j++)
add_edge(0, i, t[j] - t[j - 1], c[j]);
add_edge(0, i, 1000000007, c[x + 1]);
for(RG int j = 1; j <= m; j++)
if(g[i][j]) add_edge(i, j + n, 1000000007, 0);
}
MinCostMaxFlow();
printf("%lld\n", cost);
return 0;
}

【SDOI2011】工作安排的更多相关文章

  1. bzoj 2245 [SDOI2011]工作安排(最小费用最大流)

    2245: [SDOI2011]工作安排 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1197  Solved: 580[Submit][Statu ...

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

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

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

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

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

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

  5. 【BZOJ 2245】[SDOI2011]工作安排

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

  6. [SDOI2011]工作安排

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

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

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

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

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

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

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

  10. 【bzoj2245】 SDOI2011—工作安排

    http://www.lydsy.com/JudgeOnline/problem.php?id=2245 (题目链接) 题意 n个产品,每个需要造C[i]件:m个员工,每个员工可以制造一些产品:每个员 ...

随机推荐

  1. Oracle特殊恢复原理与实战(DSI系列)

    1.深入浅出Oracle(DSI系列Ⅰ) 2.Oracle特殊恢复原理与实战(DSI系列Ⅱ) 3.Oracle SQL Tuning(DSI系列Ⅲ)即将开设 4.Oracle DB Performan ...

  2. 转:Window_Open详解

       引:Window_Open详解一.window.open()支持环境:JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二.基本语法:window.op ...

  3. Linux 新建用户和组命令

    用户的角色是通过UID和GID识别的. UID用户ID:相当于各为的身份证,在系统中是唯一的 GID组ID:相当于各为的家庭或者你们的学校. 1.新建用户及设置密码命令如下: useradd [参数] ...

  4. 心灵鸡汤[all]

    1. [iPhone 有哪些非常有必要下载的 App] 2. 相 信 自 己 3. 英语四级作文模板 4. 比尔盖茨的人生忠告 5. 李嘉诚 <Are you ready> 6. 李嘉诚语 ...

  5. Build path entry is missing: config 引起的 The project: configwhich is referenced by the classpath, does not exist.

    运行Junit的时候报错, The project: XXXX which is referenced by the classpath, does not exist. 在Java Build Pa ...

  6. 铁乐学python27_模块学习2

    大部份内容摘自博客http://www.cnblogs.com/Eva-J/ collections模块 在内置数据类型(dict.list.set.tuple)的基础上, collections模块 ...

  7. spring4声明式事务—02 xml配置方式

    1.配置普通的 controller,service ,dao 的bean. <!-- 配置 dao ,service --> <bean id="bookShopDao& ...

  8. oracle监听,数据库,oracle服务器的启动和停用

    一.oracle监听,数据库,oracle服务器的启动和停用 使用root用户登录:切换用户su – root/root操作系统,一般只有root用户才有权限去操作系统中安装的oracle数据库服务器 ...

  9. ZT 计算一个无符整数中1Bit的个数(1) 2010-04-20 10:52:48

    计算一个无符整数中1Bit的个数(1) 2010-04-20 10:52:48 分类: C/C++ [转]计算一个无符整数中1Bit的个数(1)   Count the number of bits ...

  10. 《面向对象程序设计》 三 Calculator 计算器初步

    Git传送门 纸上得来终觉浅,绝知此事要躬行. 学习了一些c++的相应知识后,虽然了解写法,真正操作时还是出现小错误.要多操作,记住关键点,避免不该有的小错误. 写分文件类外定义时出现了问题.在Sca ...