[SHOI 2017] 寿司餐厅
[题目链接]
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] 寿司餐厅的更多相关文章
- 【BZOJ4873】[六省联考2017]寿司餐厅(网络流)
[BZOJ4873][六省联考2017]寿司餐厅(网络流) 题面 BZOJ 洛谷 题解 很有意思的题目 首先看到答案的计算方法,就很明显的感觉到是一个最大权闭合子图. 然后只需要考虑怎么构图就行了. ...
- bzoj千题计划265:bzoj4873: [六省联考2017]寿司餐厅
http://www.lydsy.com/JudgeOnline/problem.php?id=4873 选a必选b,a依赖于b 最大权闭合子图模型 构图: 1.源点 向 正美味度区间 连 流量为 美 ...
- [BZOJ4873][六省联考2017]寿司餐厅(最大权闭合子图)
4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 490 Solved: 350[Submit][Status ...
- P3749 [六省联考2017]寿司餐厅 最小割
\(\color{#0066ff}{ 题目描述 }\) Kiana 最近喜欢到一家非常美味的寿司餐厅用餐. 每天晚上,这家餐厅都会按顺序提供 \(n\) 种寿司,第 \(i\) 种寿司有一个代号 \( ...
- 【洛谷P3749】[六省联考2017]寿司餐厅(网络流)
洛谷 题意: 给出\(n\)份寿司,现可以选取任意多次连续区间内的寿司,对于区间\([l,r]\),那么贡献为\(\sum_{i=l}^r \sum_{j=i}^rd_{i,j}\)(对于相同的\(d ...
- 洛谷$P3749$ [六省联考2017] 寿司餐厅 网络流
正解:网络流 解题报告: 传送门$QwQ$ 这道题好烦昂,,,就给了好多变量,,,但仔细读一遍题还是能$get$的所以我就不再提取一遍题目大意辣$QwQ$? 显然考虑建两排点,一排收益一排支出然后最小 ...
- 洛谷P3749 [六省联考2017]寿司餐厅
传送门 题解 这几道都是上周llj讲的题,题解也写得十分好了,所以直接贴了几个链接和代码. //Achen #include<algorithm> #include<iostream ...
- 2017 [六省联考] T6 寿司餐厅
4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 450 Solved: 316[Submit][Status ...
- 【最大权闭合子图】bzoj4873 [Shoi2017]寿司餐厅
4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 369 Solved: 256[Submit][Status ...
随机推荐
- httplib 和 httplib2区别之 gzip解压
HTTP请求头Accept-encoding: gzip信息告诉服务器,如果它有任何新数据要发送给时,请以压缩的格式发送.如果服务器支持压缩,它将返回由 gzip 压缩的数据并且使用Content-e ...
- Eclipse 安装(Oxygen版本)
Eclipse 安装(Oxygen版本) Eclipse 最新版本 Eclipse Neon,这个首次鼓励用户使用 Eclipse Installer 来做安装,这是一种由Eclipse Oomph提 ...
- vue2.0 自定义 饼状图 (Echarts)组件
1.自定义 图表 组件 Echarts.vue <!-- 自定义 echart 组件 --> <template> <div> <!-- echart表格 ...
- redis 3.0.1 在CentOS上的安装
一.下载 wget http://download.redis.io/releases/redis-3.0.1.tar.gz 二.解压 tar xzf redis-3.0.1.tar.gz 三.进入 ...
- Can't open named pipe to host: . pipe: MySQL
今天遇到mysql连接odbc时报例如以下错误:Can't open named pipe to host: . pipe: MySQL 错误截图例如以下: 依照网上说的方法包含mysql的官方说法都 ...
- 关于提高沟通能力的书单 | 章鱼书单zz
上周推荐了一份关于提高写作能力的书单,这周,我们来聊聊沟通能力. 在现代社会,沟通能力变得越来越重要.人与人之间的社交渠道越来越丰富,工作中的协同合作也越来越普遍.我们要沟通的人越来越多,节奏越来越快 ...
- 我的Android进阶之旅------>Android中android:windowSoftInputMode的使用方法
面试题:怎样在显示某个Activity时马上弹出软键盘? 答案:在AndroidManifest.xml文件里设置<activity>标签的android:windowSoftInputM ...
- 服务管理-Nginx
nginx优势 select,epoll模型 对于一次IO访问(以read举例),数据会先被拷贝到操作系统内核的缓冲区中,然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间.所以说.当一个read ...
- align="absmiddle" 图片的中间上下对齐
align=absmiddle表示图像的中间与同一行中最大元素的中间对齐 AbsBottom 图像的下边缘与同一行中最大元素的下边缘对齐.AbsMiddle 图像的中间与同一行中最大元素的中间对齐.B ...
- ContentPresenter理解
这是2年前写了一篇文章 http://www.cnblogs.com/Clingingboy/archive/2008/07/03/wpfcustomcontrolpart-1.html 我们先来看M ...