【SDOI2011】工作安排
题面
题解
如果没有分段函数的限制的话就很好做了
但是我们发现分段函数的段很少,我们就可以将每一段拆开,
强制限制一定流量就可以了
代码
#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】工作安排的更多相关文章
- bzoj 2245 [SDOI2011]工作安排(最小费用最大流)
2245: [SDOI2011]工作安排 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1197 Solved: 580[Submit][Statu ...
- BZOJ 2245: [SDOI2011]工作安排( 费用流 )
费用流模板题..限制一下不同愤怒值的工作数就可以了. ------------------------------------------------------------------------- ...
- 【BZOJ2245】[SDOI2011]工作安排(费用流)
[BZOJ2245][SDOI2011]工作安排(费用流) 题面 BZOJ 洛谷 题解 裸的费用流吧. 不需要拆点,只需要连边就好了,保证了\(W_j<W_{j+1}\). #include&l ...
- 【BZOJ2245】[SDOI2011]工作安排 拆边费用流
[BZOJ2245][SDOI2011]工作安排 Description 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被 ...
- 【BZOJ 2245】[SDOI2011]工作安排
Description 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产 ...
- [SDOI2011]工作安排
Description 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产 ...
- 【bzoj2245】[SDOI2011]工作安排 费用流
题目描述 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产品必须完整地由 ...
- BZOJ2245 [SDOI2011]工作安排 【费用流】
题目 你的公司接到了一批订单.订单要求你的公司提供n类产品,产品被编号为1~n,其中第i类产品共需要Ci件.公司共有m名员工,员工被编号为1~m员工能够制造的产品种类有所区别.一件产品必须完整地由一名 ...
- P2488 [SDOI2011]工作安排 费用流
\(\color{#0066ff}{ 题目描述 }\) 你的任务是制定出一个产品的分配方案,使得订单条件被满足,并且所有员工的愤怒值之和最小.由于我们并不想使用Special Judge,也为了使选手 ...
- 【bzoj2245】 SDOI2011—工作安排
http://www.lydsy.com/JudgeOnline/problem.php?id=2245 (题目链接) 题意 n个产品,每个需要造C[i]件:m个员工,每个员工可以制造一些产品:每个员 ...
随机推荐
- ARC下的block导致的循环引用问题解析
ARC下的block导致的循环引用问题解析 更详细细节请参考 http://blog.sina.com.cn/s/blog_8c87ba3b0101m599.html ARC下,copy到堆上的blo ...
- [翻译] ios-image-filters
ios-image-filters https://github.com/esilverberg/ios-image-filters photoshop-style filter interface ...
- 用于mask遮罩效果的图片配合resizableImage使用
用于mask遮罩效果的图片配合resizableImage使用 效果: 作为素材用的图片: 源码: // // ViewController.m // Rect // // Created by Yo ...
- UIImagePickerController按钮的中文问题
UIImagePickerController按钮的中文问题 执行以下两步即可 1. 在targets中设置region为China 2. 在project中添加支持中文
- [EffectiveC++]item27:尽量少做转型动作
- ASP.NET MVC 3 Performance – on par with MVC 2
http://blogs.msdn.com/b/marcinon/archive/2011/01/17/mvc-3-performance.aspx ASP.NET MVC 3 Performance ...
- Ajax请求:本地跨域的问题
问题出现一: 1.Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-e ...
- LRU算法的精简实现(基于Java)
LRU(Least recently used,最近最少使用)算法根据数据的历史访问记录来进行淘汰数据,其核心思想是"如果数据最近被访问过,那么将来被访问的几率也更高". impo ...
- ubuntu常见问题排查
1. ubuntu recovery mode read-only 获取写的权限 1.1. 选择fsck check all file systems 进去直接选择YES就可以了 1.2. 选择roo ...
- ABAP知识点提纲
编号 课程名称 课程内容 预计课时 10.1.1~10.1.2 SAP系统与产品集 1. 了解SAP常见产品 ,了解SAP系统架构 1 10.1.3~10.1.4 导航界面与用户界面 1. 了解SAP ...