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辆车分别从上端和左端出发,如果在行驶的过程中需要转换 ...
随机推荐
- glade2支持C++代码的输出(3)
今天完成了glade-2生成configure.ac/Makefile.am等调整 代码为:cpp_out_4.patch.zip BaseObject类也做了一些小的调整:BaseObject.00 ...
- stamp-po的作用
stamp-po是表示po文件是否有更新,有更新,则重新编译一次
- quartz_jobs.xml标准配置
<?xml version="1.0" encoding="UTF-8"?><job-scheduling-data xmlns=" ...
- android studio中ListView与SQLite的结合使用
Da.java public class Db extends SQLiteOpenHelper { public Db(Context context) { super(context, " ...
- e_msg_c_as_register_req-注册存储过程
TOP:BEGIN #Routine body goes here... IF EXISTS ( SELECT * FROM `global_account` WHERE `plantform_id` ...
- 药企信息sop
中国药品生产企业 http://db.yaozh.com/shengchanqiye 全球药品生产企业 http://db.yaozh.com/quanqiuqiye
- 最大似然估计 (MLE) 最大后验概率(MAP)
1) 最大似然估计 MLE 给定一堆数据,假如我们知道它是从某一种分布中随机取出来的,可是我们并不知道这个分布具体的参,即"模型已定,参数未知". 例如,我们知道这个分布是正态分布 ...
- Java——文件选择框:JFileChooser
import java.awt.BorderLayout; import java.awt.Container; import java.awt.event.ActionEvent; import j ...
- 正则匹配IP
分析 IP地址的长度为32位,分为4段,每段8位,用十进制数字表示,每段数字范围为0~255( 2^8 ),段与段之间用英文句点“.”隔开.例如:某台计算机IP地址为10.11.44.100. IP地 ...
- Win7系统中提示:本地无法启动MySQL服务,报的错误:1067,进程意外终止的解决方法。
Win7系统中提示:本地无法启动MySQL服务,报的错误:1067,进程意外终止的解决方法. 在本地计算机无法启动MYSQL服务错误1067进程意外终止.这种情况一般是my.ini文件配置出错了1.首 ...