[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=4873

[算法]

注意到题目中的限制条件可表述为 : 若选择区间[L , R] , 则必须选择区间[L + 1 , R]和[L , R - 1] , 这种依赖关系可以让我们联想到用最大权闭合子图解题

将每种代号建一个点 , 每个区间同样建一个点

首先将每个形如[i , i]的区间向其代号连边

然后将每个区间[L , R]所代表的点向[L + 1 , R]和[L , R - 1]连边

注意我们需要减去代价mx ^ 2 + cx

那么我们将每个形如[i , i]的区间所代表点的点权减去其代号 , 将每种代号i所代表点的点权减去m * i ^ 2

时间复杂度 : O(Dinic(N ^ 2 , N ^ 2))

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = ;
const int inf = 2e9; struct edge
{
int to , w , nxt;
} e[N * N * ]; int n , m , cnt , mx , S , T , tot;
int d[N][N] , a[N * ] , point[N][N] , head[N * N * ] , dep[N * N * ]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void addedge(int u , int v , int w)
{
++tot;
e[tot] = (edge){v , w , head[u]};
head[u] = tot;
++tot;
e[tot] = (edge){u , , head[v]};
head[v] = tot;
}
inline bool bfs()
{
queue< int > q;
for (int i = ; i <= T; ++i)
dep[i] = -;
q.push(S);
dep[S] = ;
while (!q.empty())
{
int cur = q.front();
q.pop();
for (int i = head[cur]; i; i = e[i].nxt)
{
int v = e[i].to , w = e[i].w;
if (w > && dep[v] == -)
{
dep[v] = dep[cur] + ;
q.push(v);
if (v == T) return true;
}
}
}
return false;
}
inline int dinic(int u , int flow)
{
int k , rest = flow;
if (u == T)
return flow;
for (int i = head[u]; i && rest; i = e[i].nxt)
{
int v = e[i].to , w = e[i].w;
if (w > && dep[v] == dep[u] + )
{
k = dinic(v , min(rest , w));
e[i].w -= k;
e[i ^ ].w += k;
if (!k) dep[v] = ;
rest -= k;
}
}
return flow - rest;
} int main()
{ read(n); read(m);
tot = ;
for (int i = ; i <= n; ++i)
{
read(a[i]);
mx = max(mx , a[i]);
}
cnt = mx;
for (int i = ; i <= n; ++i)
{
for (int j = i; j <= n; ++j)
{
read(d[i][j]);
point[i][j] = ++cnt;
}
}
S = cnt + , T = S + ;
int ans = ;
for (int i = ; i <= n; ++i) d[i][i] -= a[i];
for (int i = ; i <= mx; ++i) addedge(i , T , m * i * i);
for (int i = ; i <= n; i++) addedge(point[i][i] , a[i] , inf);
for (int i = ; i <= n; ++i)
{
for (int j = i; j <= n; ++j)
{
if (i <= j - )
addedge(point[i][j] , point[i][j - ] , inf);
if (i + <= j)
addedge(point[i][j] , point[i + ][j] , inf);
if (d[i][j] >= )
{
ans += d[i][j];
addedge(S , point[i][j] , d[i][j]);
} else addedge(point[i][j] , T , -d[i][j]);
}
}
while (bfs())
{
while (int flow = dinic(S , inf))
ans -= flow;
}
printf("%d\n" , ans); return ; }

[SHOI 2017] 寿司餐厅的更多相关文章

  1. 【BZOJ4873】[六省联考2017]寿司餐厅(网络流)

    [BZOJ4873][六省联考2017]寿司餐厅(网络流) 题面 BZOJ 洛谷 题解 很有意思的题目 首先看到答案的计算方法,就很明显的感觉到是一个最大权闭合子图. 然后只需要考虑怎么构图就行了. ...

  2. bzoj千题计划265:bzoj4873: [六省联考2017]寿司餐厅

    http://www.lydsy.com/JudgeOnline/problem.php?id=4873 选a必选b,a依赖于b 最大权闭合子图模型 构图: 1.源点 向 正美味度区间 连 流量为 美 ...

  3. [BZOJ4873][六省联考2017]寿司餐厅(最大权闭合子图)

    4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 490  Solved: 350[Submit][Status ...

  4. P3749 [六省联考2017]寿司餐厅 最小割

    \(\color{#0066ff}{ 题目描述 }\) Kiana 最近喜欢到一家非常美味的寿司餐厅用餐. 每天晚上,这家餐厅都会按顺序提供 \(n\) 种寿司,第 \(i\) 种寿司有一个代号 \( ...

  5. 【洛谷P3749】[六省联考2017]寿司餐厅(网络流)

    洛谷 题意: 给出\(n\)份寿司,现可以选取任意多次连续区间内的寿司,对于区间\([l,r]\),那么贡献为\(\sum_{i=l}^r \sum_{j=i}^rd_{i,j}\)(对于相同的\(d ...

  6. 洛谷$P3749$ [六省联考2017] 寿司餐厅 网络流

    正解:网络流 解题报告: 传送门$QwQ$ 这道题好烦昂,,,就给了好多变量,,,但仔细读一遍题还是能$get$的所以我就不再提取一遍题目大意辣$QwQ$? 显然考虑建两排点,一排收益一排支出然后最小 ...

  7. 洛谷P3749 [六省联考2017]寿司餐厅

    传送门 题解 这几道都是上周llj讲的题,题解也写得十分好了,所以直接贴了几个链接和代码. //Achen #include<algorithm> #include<iostream ...

  8. 2017 [六省联考] T6 寿司餐厅

    4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 450  Solved: 316[Submit][Status ...

  9. 【最大权闭合子图】bzoj4873 [Shoi2017]寿司餐厅

    4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 369  Solved: 256[Submit][Status ...

随机推荐

  1. mysql_config_editor使用简介

      原文 : http://blog.itpub.net/29773961/viewspace-1817640/   ----------------------------------------- ...

  2. spring secrity 一些常用小知识

    1.在JSP页面获取当前登录的用户名的方法 首先引入taglib:<%@ taglib prefix="sec" uri="http://www.springfra ...

  3. vue2.0 自定义 弹窗(MessageBox)组件

    组件模板 src/components/MessageBox/index.vue <!-- 自定义 MessageBox 组件 --> <template> <div c ...

  4. odoo小数精确度

    python round() 函数     Python用于四舍五入的内建函数round() ,它的定义为 意思是, 将 小数部分保留到 ndigits 指定的 小数位,也就是 精度保持到 ndigi ...

  5. flex 节点删除

    <mx:Script>        <![CDATA[            protected function btn1_clickHandler(evt:MouseEvent ...

  6. Windows下编程2----- C语言常用函数举例

    几个小函数 1.    //MessageBoxA(0,"网络故障,重新登录","qq error",3); //弹出对话框 2.    //ShellExec ...

  7. CSS3中的动画效果-------Day72

    还记得么,在前面也曾实现过"仅仅用css让div动起来",还记得当时是怎么实现的么,是的,transition,针对的也比較局限,仅仅有旋转角度啊,长宽啊之类的,所以说,与其说是动 ...

  8. 关于Swiper(概念)

    Swiper 是一款免费以及轻量级的移动设备触控滑块的js框架,使用硬件加速过渡(如果该设备支持的话). 主要使用于移动端的网站.移动web apps,native apps和hybrid apps. ...

  9. C# 将cookie写入WebBrowser

    string cookie = ""; foreach (string c in cookie.Split(';')) { string[] item = c.Split('=') ...

  10. PHP中的$_SERVER['PATH_INFO']

    PHP中的全局变量$_SERVER['PATH_INFO']是一个很有用的参数,众多的CMS系统在美化自己的URL的时候,都用到了这个参数. 对于下面这个网址: http://www.test.com ...