3144

思路:

  xxy;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 64005
#define INF 0x3f3f3f3f
const int dx[]={,-,,,};
const int dy[]={,,,,-};
int deep[maxn],head[maxn],E[maxn<<],V[maxn<<],F[maxn<<],ans;
int n,m,r,d,ai[][][],id[][][],s,t,cnt,que[maxn];
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void edge_add(int u,int v,int f)
{
E[++cnt]=head[u],V[cnt]=v,F[cnt]=f,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,F[cnt]=,head[v]=cnt;
}
bool bfs()
{
for(int i=s;i<=t;i++) deep[i]=-;
deep[s]=,que[]=s;int h=,tail=,now;
while(h<tail)
{
now=que[h++];
for(int i=head[now];i;i=E[i])
if(F[i]&&deep[V[i]]<)
{
deep[V[i]]=deep[now]+;
if(V[i]==t) return true;
que[tail++]=V[i];
}
}
return false;
}
int flowing(int now,int flow)
{
if(now==t||flow<=) return flow;
int oldflow=,pos;
for(int i=head[now];i;i=E[i])
{
if(deep[V[i]]!=deep[now]+||!F[i]) continue;
pos=flowing(V[i],min(flow,F[i]));
F[i]-=pos,F[i^]+=pos,flow-=pos,oldflow+=pos;
if(!flow) return oldflow;
}
if(!oldflow) deep[now]=-;
return oldflow;
}
int main()
{
in(n),in(m),in(r),in(d);
for(int i=;i<=r;i++)
for(int v=;v<=n;v++)
for(int e=;e<=m;e++) in(ai[i][v][e]),id[i][v][e]=++cnt;
s=,t=cnt+,cnt=;
for(int i=;i<=n;i++)
for(int v=;v<=m;v++)
edge_add(s,id[][i][v],ai[][i][v]),edge_add(id[r][i][v],t,INF);
for(int z=;z<=r;z++)
{
for(int i=;i<=n;i++)
for(int v=;v<=m;v++) edge_add(id[z-][i][v],id[z][i][v],ai[z][i][v]);
if(z>d)
{
for(int i=;i<=n;i++)
for(int v=;v<=m;v++)
for(int e=;e<=;e++)
if(i+dx[e]>&&i+dx[e]<=n&&v+dy[e]>&&v+dy[e]<=m)
edge_add(id[z][i][v],id[z-d][i+dx[e]][v+dy[e]],INF);
}
}
while(bfs()) ans+=flowing(s,INF);
printf("%d\n",ans);
return ;
}

bzoj 3144的更多相关文章

  1. [BZOJ 3144] [Hnoi2013] 切糕 【最小割】

    题目链接:BZOJ - 3144 题目分析 题意:在 P * Q 的方格上填数字,可以填 [1, R] . 在 (x, y) 上填 z 会有 V[x][y][z] 的代价.限制:相邻两个格子填的数字的 ...

  2. [BZOJ 3144] 切糕

    Link: BZOJ 3144 传送门 Solution: 发现要把点集分成不连通的两部分,最小割的模型还是很明显的 首先我们将原图转化为$R+1$层,从而将点权化为边权 关键还是在于建图是怎么保证$ ...

  3. [BZOJ 3144][HNOI 2013] 切糕

    题目大意 切糕是 (p times q times r) 的长方体,每个点有一个违和感 (v_{x, y, z}).先要水平切开切糕(即对于每个纵轴,切面与其有且只有一个交点),要求水平上相邻两点的切 ...

  4. BZOJ 3144: [Hnoi2013]切糕

    3144: [Hnoi2013]切糕 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1495  Solved: 819[Submit][Status] ...

  5. BZOJ 3144 切糕(最小割)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3144 题意: 思路:我们假设没有那个D的限制.这样就简 单了.贪心的话,我们只要在每一个 ...

  6. bzoj 3144: [Hnoi2013]切糕 最小割

    3144: [Hnoi2013]切糕 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 681  Solved: 375[Submit][Status] ...

  7. bzoj 3144 [Hnoi2013]切糕——最小割

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3144 一根纵轴上切一个点,可以把一根纵轴上的点连成一串来体现.自己的写法是每个点连向前一个点 ...

  8. 【BZOJ 3144】 3144: [Hnoi2013]切糕 (最小割模型)

    3144: [Hnoi2013]切糕 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1764  Solved: 965 Description Inp ...

  9. bzoj 3144 切糕 —— 最小割

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3144 每个点拆成 R 个,连成一条链,边上是权值,割掉代表选这一层: 然后每个点的第 t 层 ...

随机推荐

  1. IntelliJIDEA永久注册使用

    1. 首先下载本地IntelliJIDEA注册服务机(没有密码哦) http://pan.baidu.com/s/1hsyZp0C 2.解压后进入解压的文件夹,找到自己操作系统对应的版本,我这里使用 ...

  2. Bittersweet——NOIP2018 游记

    p { font-size: 16px; line-height: 1.5em; } blockquote { font-family: 'Times New Roman', 楷体; text-ali ...

  3. 微信网页动画---swiper.animate.css

    项目需要,自己写了个demo <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  4. 连接mysql提示Establishing SSL connection without server's identity verification is not recommended错误

    Establishing SSL connection without server's identity verification is not recommended. According to ...

  5. 七牛云 上传图片 https 修改Nginx 注意事项

    仅在这记录下,今天的事情. 问题出自于Nginx 设置http 强制跳转 https设置 1.上午,出于某些需求,我将服务器Nginx 设置http 强行跳转 https server { liste ...

  6. 训练赛第二场G题 ZOJ 2343

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2343 解题报告:首先我假设最后的正确的结果是a[1] , a[2 ...

  7. python正则表达式-re模块的爱恨情仇

    利用python的re模块,使用正则表达式对字符串进行处理 # 编辑者:闫龙 import re restr = "abccgccc123def456ghi789jgkl186000&quo ...

  8. HaoZipC不是内部或外部命令

    Win7专业版,32位,HaoZip V3.2 将安装命令下HaoZipC.exe,HaoZip.dll,lang\HaoZipLang_chs.dll三个文件拷贝到C:\Windows\System ...

  9. 『实践』百度地图给多个marker添加右键菜单(删除、更新)

    js: $.getJSON("./GetStationPlaceServlet",function(json){ for(var i=0;i<json.length;i++) ...

  10. STM32 IAP升级

    STM32 IAP在线升级,用Jlink设置读保护后前5K字节是默认加了写保护的,导致IAP升级时擦除和写入FLASH不成功,可以做两个boot,前5k为第一个boot程序,上电时负责跳转到APP还是 ...