\(\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}\)

/* Clearink */

#include <queue>
#include <cstdio>
#include <cassert>
#include <algorithm> #define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i )
#define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i ) typedef std::pair<int, int> PII; inline int rint () {
int x = 0; char s = getchar ();
for ( ; s < '0' || '9' < s; s = getchar () );
for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
return x;
} inline int imin ( const int a, const int b ) { return a < b ? a : b; } const int MAXN = 40, MAXM = 100, MAXND = 1e4, INF = 0x3f3f3f3f;
int n, m, cook[MAXN + 5][MAXM + 5], bel[MAXND + 5], stp[MAXM + 5], vis[MAXND + 5]; struct MaxFlowCostGraph {
static const int MAXND = ::MAXND, MAXEG = 2e6;
int ecnt, head[MAXND + 5], S, T, bound, curh[MAXND + 5], d[MAXND + 5];
bool inq[MAXND + 5];
struct Edge { int to, flw, cst, nxt; } graph[MAXEG * 2 + 5]; MaxFlowCostGraph (): ecnt ( 1 ) {} inline void link ( const int s, const int t, const int f, const int w ) {
graph[++ecnt] = { t, f, w, head[s] };
head[s] = ecnt;
} inline Edge& operator [] ( const int k ) { return graph[k]; } inline void operator () ( const int s, const int t, const int f, const int w ) {
#ifdef RYBY
printf ( "%d %d ", s, t );
if ( f == INF ) printf ( "INF " );
else printf ( "%d ", f );
printf ( "%d\n", w );
#endif
link ( s, t, f, w ), link ( t, s, 0, -w );
} inline bool spfa () {
static std::queue<int> que;
for ( int i = 0; i <= bound; ++i ) d[i] = -1, inq[i] = false;
d[S] = 0, inq[S] = true, que.push ( S );
while ( !que.empty () ) {
int u = que.front (); que.pop ();
inq[u] = false;
for ( int i = head[u], v; i; i = graph[i].nxt ) {
if ( graph[i].flw
&& ( !~d[v = graph[i].to] || d[v] > d[u] + graph[i].cst ) ) {
d[v] = d[u] + graph[i].cst;
if ( !inq[v] ) que.push ( v ), inq[v] = true;
}
}
}
return ~d[T];
} inline PII dfs ( const int u, const int iflw ) {
if ( u == T ) return { iflw, 0 };
inq[u] = true; PII ret ( 0, 0 );
for ( int& i = curh[u], v; i; i = graph[i].nxt ) {
if ( graph[i].flw && !inq[v = graph[i].to]
&& d[v] == d[u] + graph[i].cst ) {
PII oflw ( dfs ( v, imin ( iflw - ret.first, graph[i].flw ) ) );
graph[i].flw -= oflw.first, graph[i ^ 1].flw += oflw.first;
ret.first += oflw.first;
ret.second += graph[i].cst * oflw.first + oflw.second;
if ( ret.first == iflw ) break;
}
}
if ( !ret.first ) d[u] = -1;
return inq[u] = false, ret;
}
} graph; int main () {
n = rint (), m = rint ();
int S = 0, T = graph.bound = 1e4, cnt = n;
rep ( i, 1, n ) graph ( S, i, rint (), 0 );
rep ( i, 1, n ) rep ( j, 1, m ) cook[i][j] = rint ();
rep ( i, 1, m ) {
graph ( ++cnt, T, 1, 0 ), bel[cnt] = i, stp[i] = 1;
rep ( j, 1, n ) graph ( j, cnt, 1, cook[j][i] );
}
graph.S = S, graph.T = T;
int ans = 0;
while ( graph.spfa () ) {
for ( int i = 0; i <= graph.bound; ++i ) {
graph.inq[i] = false, graph.curh[i] = graph.head[i];
}
ans += graph.dfs ( S, INF ).second;
for ( int i = graph.head[T], v, cid; i; i = graph[i].nxt ) {
if ( graph[i].flw && !vis[v = graph[i].to] ) {
vis[v] = true, cid = bel[v];
graph ( ++cnt, T, 1, 0 ), ++stp[bel[cnt] = cid];
rep ( j, 1, n ) graph ( j, cnt, 1, stp[cid] * cook[j][cid] );
}
}
}
printf ( "%d\n", ans );
return 0;
}

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. 关于APP设计规范和一些图层命名

    首先,本人大学计算机专业出身,学过编程,工作的时候做过 产品经理,设计师,前端工程师,对工作的流程都有一些见解. 现在主攻前端工程师,做Web APP.今天收到设计师的设计稿,一看图层分类,这让我感觉 ...

  2. 【Spring专场】「MVC容器」不看源码就带你认识核心流程以及运作原理

    前提回顾 之前已经写了很多问斩针对于SpringMVC的的执行原理和核心流程,在此再进行冗余介绍就没有任何意义了,所以我们主要考虑的就是针对于SpringMVC还没但大框架有介绍的相关内容解析分析和说 ...

  3. ​第3届云原生技术实践峰会(CNBPS 2020)重磅开启,“原”力蓄势待发!

    CNBPS 2020将在11月19-21日全新启动!作为国内最有影响力的云原生盛会之一,云原生技术实践峰会(CNBPS)至今已举办三届. 在2019年的CNBPS上,灵雀云CTO陈恺喊出"云 ...

  4. 【C primer plus】初始化链表函数的错误

    C primer plus第六版 的一处错误 第五百页17.3.4 实现接口的程序清单17.5中的初始化链表函数有误 #源代码 void InitializeList(List * plist) { ...

  5. Ubuntu 18.04 server安装+搭建Seacms v10.1网站

    0x00 写在前面 以前我天真的认为,ubuntu Desktop会安装了,server就无所谓了,其实完全不然,server还是有一些坑点的. 之所以选择Seacms搭建网站,是因为这个SeaCMS ...

  6. day 10 删除空白字符

    (1).有以下程序(大写变小写) (2).有以下程序,在[1]填写程序,使得程序正确运行. 分析:(*p)(int,int)是一个函数指针(一个指针[*p]指向的对象是一个函数),函数的形参是(int ...

  7. python极简教程08:对象的方法

    测试奇谭,BUG不见. 讲解之前,我先说说我的教程和网上其他教程的区别: 1 我分享的是我在工作中高频使用的场景,是精华内容: 2 我分享的是学习方法,亦或说,是指明你该学哪些.该重点掌握哪些内容: ...

  8. ComboBox行高

    //行高至少大于20 public static void SetComboBoxLineHeight(ComboBox list, int itemHeight) { list.DropDownSt ...

  9. Django class meta

    class Main(models.Model): img = models.CharField(max_length=200) # 图片 name = models.CharField(max_le ...

  10. JavaScript多元运算符

    JavaScript多元运算符   JavaScript多元运算符 **实例:**` function test(9){ var a=4,b=11; return p > 1 ? p<b ...