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

你的任务是制定出一个产品的分配方案,使得订单条件被满足,并且所有员工的愤怒值之和最小。由于我们并不想使用Special Judge,也为了使选手有更多的时间研究其他两道题目,你只需要输出最小的愤怒值之和就可以了。

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

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

仅输出一个整数,表示最小的愤怒值之和。

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

  1. 2 3
  2. 2 2 2
  3. 1 1 0
  4. 0 0 1
  5. 1
  6. 2
  7. 1 10
  8. 1
  9. 2
  10. 1 6

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

  1. 24

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

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

显然是个费用流

考虑怎么建边

愤怒值对于每个员工完成工作的数量来分段

完成工作数量? 这不就是从员工流出去多少流吗

所以,从S向员工,连多条边,每条边的容量为每段的长

这样愤怒值的问题就解决了

注意,每个任务不止完成一次

所以员工向任务连容量为inf的边,任务向T连容量为需要次数的边

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. LL in() {
  4. char ch; LL x = 0, f = 1;
  5. while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
  6. for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
  7. return x * f;
  8. }
  9. const int maxn = 1e5;
  10. const LL inf = 999999999999999LL;
  11. struct node {
  12. int to;
  13. LL dis, can;
  14. node *nxt, *rev;
  15. node(int to = 0, LL dis = 0, LL can = 0, node *nxt = NULL)
  16. : to(to), dis(dis), can(can), nxt(nxt) {}
  17. void *operator new (size_t) {
  18. static node *S = NULL, *T = NULL;
  19. return (S == T) && (T = (S = new node[1024]) + 1024), S++;
  20. }
  21. };
  22. LL dis[maxn], change[maxn];
  23. node *head[maxn], *road[maxn];
  24. bool vis[maxn];
  25. bool f[505][505];
  26. int n, s, t, m;
  27. std::vector<LL> v[maxn], d[maxn];
  28. bool spfa() {
  29. for(int i = s; i <= t; i++) dis[i] = inf, change[i] = inf;
  30. std::queue<int> q;
  31. dis[s] = 0;
  32. q.push(s);
  33. while(!q.empty()) {
  34. int tp = q.front(); q.pop();
  35. vis[tp] = false;
  36. for(node *i = head[tp]; i; i = i->nxt)
  37. if(dis[i->to] > dis[tp] + i->dis && i->can) {
  38. dis[i->to] = dis[tp] + i->dis;
  39. change[i->to] = std::min(change[tp], i->can);
  40. road[i->to] = i;
  41. if(!vis[i->to]) vis[i->to] = true, q.push(i->to);
  42. }
  43. }
  44. return change[t] != inf;
  45. }
  46. LL mcmf() {
  47. LL cost = 0;
  48. while(spfa()) {
  49. cost += change[t] * dis[t];
  50. for(int o = t; o != s; o = road[o]->rev->to) {
  51. road[o]->can -= change[t];
  52. road[o]->rev->can += change[t];
  53. }
  54. }
  55. return cost;
  56. }
  57. void add(int from, int to, LL dis, LL can) {
  58. head[from] = new node(to, dis, can, head[from]);
  59. }
  60. void link(int from, int to, LL dis, LL can) {
  61. add(from, to, dis, can);
  62. add(to, from, -dis, 0);
  63. head[from]->rev = head[to];
  64. head[to]->rev = head[from];
  65. }
  66. int main() {
  67. m = in(), n = in();
  68. t = m + n + 1, s = 0;
  69. for(int i = m + 1; i <= m + n; i++) link(i, t, 0, in());
  70. for(int i = 1; i <= m; i++)
  71. for(int j = 1; j <= n; j++)
  72. if(in()) link(i, m + j, 0, inf);
  73. for(int i = 1; i <= m; i++) {
  74. int k = in();
  75. v[i].push_back(0);
  76. for(int j = 1; j <= k; j++) v[i].push_back(in());
  77. v[i].push_back(inf);
  78. for(int j = 1; j <= k + 1; j++) d[i].push_back(in());
  79. for(int j = 0; j <= k; j++) link(s, i, d[i][j], v[i][j + 1] - v[i][j]);
  80. }
  81. printf("%lld", mcmf());
  82. return 0;
  83. }

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

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

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

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

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

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

    题目大意: 传送门 题解: 很容易建模,把每一个工作人员拆成两个点,由第一个点向第二个点连S+1条边即可. 这水题没什么难度,主要是longlong卡的丧心病狂... 代码 #include < ...

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

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

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

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

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

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

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

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

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

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

  9. [SDOI2011][bzoj2245] 工作分配 [费用流]

    题面 传送门 思路 数据范围n,m<=250 分配任务问题 这是典型的"看到数据范围就知道算法"类型 而且我们发现我们要保证一定产出的情况下最小化花费 这句话等价于保证一定流 ...

随机推荐

  1. [转]在 Windows 操作系统中的已知安全标识符(Sid security identifiers)

    安全标识符 (SID) 是用于标识安全主体或安全组在 Windows 操作系统中的可变长度的唯一值.常用 Sid 的 Sid 标识普通用户的一组或通用组.跨所有操作系统,它们的值保持不变. 此信息可用 ...

  2. js实现大文件分片上传的方法

    借助js的Blob对象FormData对象可以实现大文件分片上传的功能,关于Blob和FormData的具体使用方法可以到如下地址去查看FormData 对象的使用Blob 对象的使用以下是实现代码, ...

  3. Python多进程-进程间数据的传递

    两个进程间的数据是独立的,要进行数据传递的话可通过几个方法 Queue 通过队列来进行进程间数据的传递 # -*- coding:utf-8 -*- __author__ = "MuT6 S ...

  4. system中有空格怎么办

    原始路径: C:\\Program Files\\putty\\putty.exe 改为: char *cmd="C:\\\"Program Files\"\\putty ...

  5. oracle——基础知识(二)未完

    1.select 查询 单独的一条 select 语句 可以一次查询多条记录:但是在 pl/sql 块中,select语句只能 使用INTO子句:必须并且只能返回一行 2.EXECUTE IMMEDI ...

  6. python jvm数据

    在网上找的抱歉忘了原链接了额 #!/usr/bin/env python # # import os import commands import re import sys (status1, re ...

  7. DAY17-Django之model增删改

    添加表记录 普通字段 #方式1 publish_obj=Publish(name="人民出版社",city="北京",email="renMin@16 ...

  8. 如何成功且顺序的进入centos系统的安全模式?(图文详解)

    说白了,这个很简单! 见 -bash : ** : command not found的问题解决(图文详解)

  9. [hdu1251]统计难题(trie模板题)

    题意:返回字典中所有以测试串为前缀的字符串总数. 解题关键:trie模板题,由AC自动机的板子稍加改造而来. #include<cstdio> #include<cstring> ...

  10. Codeforces 1136F Cooperative Game (神仙题)

    这种题就是难者不会,会者不难. 博客讲的很详细了 代码: #include <bits/stdc++.h> using namespace std; string s; int read( ...