BZOJ4439——[Swerc2015]Landscaping
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 100010
#define inf 1014748364
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
namespace dinic{
struct Edge{
int from, to, cap, flow, next;
} G[M];
int head[M], cur[M], tot;
int vis[M], d[M];
int s, t;
inline void init(){
memset(head, -1, sizeof(head));
tot = -1;
}
inline void add(int u, int v, int w){
G[++ tot] = (Edge){u, v, w, 0, head[u]};
head[u] = tot;
G[++ tot] = (Edge){v, u, 0, 0, head[v]};
head[v] = tot;
}
inline bool BFS(){
memset(vis, 0, sizeof(vis));
vis[s] = 1; d[s] = 0;
queue<int> Q; Q.push(s);
while(!Q.empty()){
int x = Q.front(); Q.pop();
for(int i = head[x]; i != -1; i = G[i].next){
Edge& e = G[i];
if(!vis[e.to] && e.cap > e.flow){
Q.push(e.to);
vis[e.to] = 1;
d[e.to] = d[x] + 1;
}
}
}
return vis[t];
}
inline int DFS(int x, int a){
if(x == t || a == 0) return a;
int flow = 0, f;
for(int& i = cur[x]; i != -1; i = G[i].next){
Edge& e = G[i];
if(d[e.to] == d[x] + 1 && (f = DFS(e.to, min(a, e.cap - e.flow))) > 0){
e.flow += f;
G[i ^ 1].flow -= f;
flow += f;
a -= f;
if(a == 0) break;
}
}
return flow;
}
inline int maxflow(){
int flow = 0;
while(BFS()){
for(int i = s; i <= t; i ++) cur[i] = head[i];
flow += DFS(s, inf);
}
return flow;
}
}
char str[60][60];
int num[60][60];
int cnt;
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
int n, m, A, B;
inline bool is_(int x, int y){
return x < 1 || y < 1 || x > n || y > m;
}
int main(){
n = read(), m = read(), A = read(), B = read();
for(int i = 1; i <= n; i ++) scanf("%s", str[i] + 1);
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
num[i][j] = ++ cnt;
}
}
dinic::init();
dinic::s = 0; dinic::t = n * m + 1;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
if(str[i][j] == '.') dinic::add(0, num[i][j], B);
else dinic::add(num[i][j], n * m + 1, B);
for(int k = 0; k < 4; k ++){
int tx = i + dx[k], ty = j + dy[k];
if(is_(tx, ty)) continue;
dinic::add(num[i][j], num[tx][ty], A);
}
}
}
printf("%d\n", dinic::maxflow());
return 0;
}
BZOJ4439——[Swerc2015]Landscaping的更多相关文章
- 【BZOJ4439】[Swerc2015]Landscaping 最小割
[BZOJ4439][Swerc2015]Landscaping Description FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地从左到右 ...
- bzoj 4439: [Swerc2015]Landscaping -- 最小割
4439: [Swerc2015]Landscaping Time Limit: 2 Sec Memory Limit: 512 MB Description FJ有一块N*M的矩形田地,有两种地形 ...
- 【bzoj4439】[Swerc2015]Landscaping 网络流最小割
题目描述 FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地从左到右完整开收割机走到头,再对每一列从上到下完整走到头,如下图所示 对于一个4*4的田 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ_4439_[Swerc2015]Landscaping_最小割
BZOJ_4439_[Swerc2015]Landscaping_最小割 Description FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地 ...
- 解决Error creating bean with name 'huayuanjingguanDaoimp' defined in file [D:\apache-tomcat-7.0.52\webapps\landscapings\WEB-INF\classes\com\itheima\landscaping\dao\imp\huayuanjingguanDaoimp.class]: Invo
问题描述: 10:23:13,585 ERROR ContextLoader:307 - Context initialization failedorg.springframework.beans. ...
- Landscaping Gym - 101128F (网络流)
Problem F: Landscaping \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 题意是给出一个\(n*m\)的格子,其中一些是低 ...
- POJ 2433 Landscaping (贪心)
题意:给定一个序列表示一群山,要你保留最多 K 个山峰,最少要削去多少体积和土.一个山峰是指一段连续的相等的区间,并且左边和右边只能比这个区间低,或者是边界. 析:贪心,每次都寻找体积最小的山峰,然后 ...
- LA 7277 Landscaping(最小割)
https://vjudge.net/problem/UVALive-7277 题意: 给出一个n*m的地图,.代表低坡,#代表高坡. 现在有n+m辆车分别从上端和左端出发,如果在行驶的过程中需要转换 ...
随机推荐
- Hibernate_增删改
package com.etc.test;import java.util.List;import org.hibernate.Session;import org.hibernate.Session ...
- WinForm------如何将GridControl数据导出到Excel
转载: http://www.cnblogs.com/xiaofengfeng/archive/2011/11/22/2258906.html 代码: SaveFileDialog saveFileD ...
- electron-Node.js Error: Module version mismatch. Expected
本来以为是nodejs的版本问题,后来才发现是electron用本地包的问题 Installing modules and rebuilding for Electron You can also c ...
- JavaScript学习笔记——函数
javascript函数的声明和调用 将完成某一特定功能的代码集合起来,可以重复使用的代码块. 一.函数的声明方式(创建) A.基本语法 function 关键字 function 函数名([参数1] ...
- Swift控制器加载xib Swift Controller'view load from xib
override func loadView() { NSBundle.mainBundle().loadNibNamed("ViewController", owner: sel ...
- idea中的svn配置
idea的使用之svn篇--有图超详细 http://ylq365.iteye.com/blog/1955291
- LINUX命令总结 -------来自 水滴娃娃 的CSDN
LINUX命令总结 标签: LINUX命令总结 2014-01-27 15:54 41039人阅读 评论(1) 收藏 举报 分类: linux(1) 版权声明:本文为博主原创文章,未经博主允许不得 ...
- CF460D Little Victor and Set (找规律)
D - Little Victor and Set Codeforces Round #262 (Div. 2) D D. Little Victor and Set time limit per t ...
- 10条PHP编程习惯助你找工作
过去的几周对我来说是一段相当复杂的经历.我们公司进行了大裁员,我是其中之一,但却体验到了其中的乐 趣.我从来没有被开除过,所以很难不去想得太多.我开始浏览招聘板块,一个全职PHP程序员的职位很吸引人, ...
- PHP文件操作 读取与写入
基本知识: PHP文件系统是基于Unix系统的 文件数据基本类型:二进制数据.文本数据 文件输入流:数据从源文件到内存的流动 文件输出流:数据从内存保存到文件的流动 文件操作函数: >>& ...