\(\mathcal{Description}\)

  Link.

  美食节提供 \(n\) 种菜品,第 \(i\) 种的需求量是 \(p_i\),菜品由 \(m\) 个厨师负责制作,第 \(j\) 个厨师做第 \(i\) 道菜的用时是 \(t_{ij}\)。安排做菜方案,使得 \(\sum p_i\) 个需求等待的总时间最小。

  \(n\le40\),\(m\le100\),\(\sum p_i\le800\)。

\(\mathcal{Solution}\)

  对于每个厨师,他做他所负责的倒数第 \(i\) 道菜的额外贡献系数为 \(i\),即其对答案贡献 \(i\times\) 做该道菜的用时。所以想到已时间为层建分层图,菜品令为 \(d_1,d_2,\cdots,d_n\),第 \(i\) 个厨师拆为 \(i_1,i_2,\cdots,i_n\),表示做倒数第 \(1\) 道菜的 \(i\) 厨师,做倒数第二道菜的 \(i\) 厨师,……,做倒数第 \(n\) 道菜的 \(i\) 厨师。每个 \(d_k\) 向 \(i_j\) 连一条费用为 \(jt_{ki}\) 的边,其余边自行脑补,跑最小费用最大流即可。

  然而 \(\mathcal O(\operatorname{Dinic}(nm,n^2m))\) 并跑不过,需要用动态加点的优化方法:当某个厨师用到了 \(i_j\) 这一虚点时,再加入 \(i_{j+1}\) 及其连边。

\(\mathcal{Code}\)

  1. /* Clearink */
  2. #include <queue>
  3. #include <cstdio>
  4. #include <cassert>
  5. #include <algorithm>
  6. #define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i )
  7. #define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i )
  8. typedef std::pair<int, int> PII;
  9. inline int rint () {
  10. int x = 0; char s = getchar ();
  11. for ( ; s < '0' || '9' < s; s = getchar () );
  12. for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
  13. return x;
  14. }
  15. inline int imin ( const int a, const int b ) { return a < b ? a : b; }
  16. const int MAXN = 40, MAXM = 100, MAXND = 1e4, INF = 0x3f3f3f3f;
  17. int n, m, cook[MAXN + 5][MAXM + 5], bel[MAXND + 5], stp[MAXM + 5], vis[MAXND + 5];
  18. struct MaxFlowCostGraph {
  19. static const int MAXND = ::MAXND, MAXEG = 2e6;
  20. int ecnt, head[MAXND + 5], S, T, bound, curh[MAXND + 5], d[MAXND + 5];
  21. bool inq[MAXND + 5];
  22. struct Edge { int to, flw, cst, nxt; } graph[MAXEG * 2 + 5];
  23. MaxFlowCostGraph (): ecnt ( 1 ) {}
  24. inline void link ( const int s, const int t, const int f, const int w ) {
  25. graph[++ecnt] = { t, f, w, head[s] };
  26. head[s] = ecnt;
  27. }
  28. inline Edge& operator [] ( const int k ) { return graph[k]; }
  29. inline void operator () ( const int s, const int t, const int f, const int w ) {
  30. #ifdef RYBY
  31. printf ( "%d %d ", s, t );
  32. if ( f == INF ) printf ( "INF " );
  33. else printf ( "%d ", f );
  34. printf ( "%d\n", w );
  35. #endif
  36. link ( s, t, f, w ), link ( t, s, 0, -w );
  37. }
  38. inline bool spfa () {
  39. static std::queue<int> que;
  40. for ( int i = 0; i <= bound; ++i ) d[i] = -1, inq[i] = false;
  41. d[S] = 0, inq[S] = true, que.push ( S );
  42. while ( !que.empty () ) {
  43. int u = que.front (); que.pop ();
  44. inq[u] = false;
  45. for ( int i = head[u], v; i; i = graph[i].nxt ) {
  46. if ( graph[i].flw
  47. && ( !~d[v = graph[i].to] || d[v] > d[u] + graph[i].cst ) ) {
  48. d[v] = d[u] + graph[i].cst;
  49. if ( !inq[v] ) que.push ( v ), inq[v] = true;
  50. }
  51. }
  52. }
  53. return ~d[T];
  54. }
  55. inline PII dfs ( const int u, const int iflw ) {
  56. if ( u == T ) return { iflw, 0 };
  57. inq[u] = true; PII ret ( 0, 0 );
  58. for ( int& i = curh[u], v; i; i = graph[i].nxt ) {
  59. if ( graph[i].flw && !inq[v = graph[i].to]
  60. && d[v] == d[u] + graph[i].cst ) {
  61. PII oflw ( dfs ( v, imin ( iflw - ret.first, graph[i].flw ) ) );
  62. graph[i].flw -= oflw.first, graph[i ^ 1].flw += oflw.first;
  63. ret.first += oflw.first;
  64. ret.second += graph[i].cst * oflw.first + oflw.second;
  65. if ( ret.first == iflw ) break;
  66. }
  67. }
  68. if ( !ret.first ) d[u] = -1;
  69. return inq[u] = false, ret;
  70. }
  71. } graph;
  72. int main () {
  73. n = rint (), m = rint ();
  74. int S = 0, T = graph.bound = 1e4, cnt = n;
  75. rep ( i, 1, n ) graph ( S, i, rint (), 0 );
  76. rep ( i, 1, n ) rep ( j, 1, m ) cook[i][j] = rint ();
  77. rep ( i, 1, m ) {
  78. graph ( ++cnt, T, 1, 0 ), bel[cnt] = i, stp[i] = 1;
  79. rep ( j, 1, n ) graph ( j, cnt, 1, cook[j][i] );
  80. }
  81. graph.S = S, graph.T = T;
  82. int ans = 0;
  83. while ( graph.spfa () ) {
  84. for ( int i = 0; i <= graph.bound; ++i ) {
  85. graph.inq[i] = false, graph.curh[i] = graph.head[i];
  86. }
  87. ans += graph.dfs ( S, INF ).second;
  88. for ( int i = graph.head[T], v, cid; i; i = graph[i].nxt ) {
  89. if ( graph[i].flw && !vis[v = graph[i].to] ) {
  90. vis[v] = true, cid = bel[v];
  91. graph ( ++cnt, T, 1, 0 ), ++stp[bel[cnt] = cid];
  92. rep ( j, 1, n ) graph ( j, cnt, 1, stp[cid] * cook[j][cid] );
  93. }
  94. }
  95. }
  96. printf ( "%d\n", ans );
  97. return 0;
  98. }

Solution -「NOI 2012」「洛谷 P2050」美食节的更多相关文章

  1. 洛谷P2050 [NOI2012]美食节

    动态加边网络流 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring ...

  2. 洛谷$P2050\ [NOI2012]$美食节 网络流

    正解:网络流 解题报告: 传送门$QwQ$ 昂开始看到$jio$得,哇长得好像上一题嗷$QwQ$ 然后仔细康康数据范围,发现,哇好像要几万个点,,,显然就$GG$了 但感$jio$思路方向好对的亚子? ...

  3. 「区间DP」「洛谷P1043」数字游戏

    「洛谷P1043」数字游戏 日后再写 代码 /*#!/bin/sh dir=$GEDIT_CURRENT_DOCUMENT_DIR name=$GEDIT_CURRENT_DOCUMENT_NAME ...

  4. Solution -「JSOI 2019」「洛谷 P5334」节日庆典

    \(\mathscr{Description}\)   Link.   给定字符串 \(S\),求 \(S\) 的每个前缀的最小表示法起始下标(若有多个,取最小的).   \(|S|\le3\time ...

  5. Solution -「洛谷 P4372」Out of Sorts P

    \(\mathcal{Description}\)   OurOJ & 洛谷 P4372(几乎一致)   设计一个排序算法,设现在对 \(\{a_n\}\) 中 \([l,r]\) 内的元素排 ...

  6. Solution -「POI 2010」「洛谷 P3511」MOS-Bridges

    \(\mathcal{Description}\)   Link.(洛谷上这翻译真的一言难尽呐.   给定一个 \(n\) 个点 \(m\) 条边的无向图,一条边 \((u,v,a,b)\) 表示从 ...

  7. Solution -「APIO 2016」「洛谷 P3643」划艇

    \(\mathcal{Description}\)   Link & 双倍经验.   给定 \(n\) 个区间 \([a_i,b_i)\)(注意原题是闭区间,这里只为方便后文描述),求 \(\ ...

  8. 「洛谷 P1801」黑匣子

    好像很久没有更过博客了,因为博主这几周很忙.其实是在搞颓. 题意很难懂,所以就不重复了.其实是懒. 一眼看上去这是个 \(Splay\) 裸题,直接插入一个数,查询区间第 \(K\) 大,但是这样太不 ...

  9. 「洛谷4197」「BZOJ3545」peak【线段树合并】

    题目链接 [洛谷] [BZOJ]没有权限号嘤嘤嘤.题号:3545 题解 窝不会克鲁斯卡尔重构树怎么办??? 可以离线乱搞. 我们将所有的操作全都存下来. 为了解决小于等于\(x\)的操作,那么我们按照 ...

随机推荐

  1. Redisson-关于使用订阅数问题

    一.前提 最近在使用分布式锁redisson时遇到一个线上问题:发现是subscriptionsPerConnection or subscriptionConnectionPoolSize 的大小不 ...

  2. 聊聊dubbo协议

    搜索关注微信公众号"捉虫大师",后端技术分享,架构设计.性能优化.源码阅读.问题排查.踩坑实践. 协议 协议通俗易懂地解释就是通信双方需要遵循的约定. 我们了解的常见的网络传输协议 ...

  3. 学习javaScript必知必会(3)~数组(数组创建,for...in遍历,辅助函数,高级函数filter、map、reduce)

    一.数组: 1.js是弱语言,js中的数组定义时:不用指定数据类型.不用功指定数组长度:数组可以存储任何数据类型的数据 2.数组定义的[ ] 的实质: [] = new Array(); {} = n ...

  4. Sentry 开发者贡献指南 - 配置 PyCharm

    概述 如果您使用 PyCharm 进行开发,则需要配置一些内容才能运行和调试. 本文档描述了一些对 sentry 开发有用的配置 配置 Python 解释器:(确保它是 venv 解释器)例如 ~/v ...

  5. cesium加载gltf模型点击以及列表点击定位弹窗

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 之 ...

  6. 实习之bii--关于虚拟机桥接无线网卡

    安装完VMware workstation之后,网络连接里会多出两个虚拟网卡: VMware Network Adapter VMnet1和VMware Network Adapter VMnet8. ...

  7. java匿名内部类-细节

    1 package face_09; 2 3 public class InnerClassDemo50 { 4 static class Inner{ 5 6 } 7 public static v ...

  8. Ubuntu安装盘的制作

    准备工作 Ubuntu系统镜像 win32diskimager U盘(4G以上),对重要文件提前备份 制作 下载系统镜像 进入官网 我们下载的版本是18.04,不是20.04 在页面中,找到BitTo ...

  9. 斯坦福 CS183 & YC 创业课系列中文笔记

    欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. 在线阅读 ApacheCN 面试求职交流群 724187166 ApacheCN 学习资源 目录 Zero to One 从0到1 ...

  10. java8 stream详细

    转载:   https://zhuanlan.zhihu.com/p/299064490