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辆车分别从上端和左端出发,如果在行驶的过程中需要转换 ...
随机推荐
- 先贴上代码:Random快排,快排的非递归实现
设要排序的数组是A[0]……A[N-1],首先任意选取一个数据(通常选用数组的第一个数)作为主元,然后将所有比它小的数都放到它前面,所有比它大的数都放到它后面,这个过程称为一趟快速排序.值得注意的是, ...
- 9月23日JavaScript作业----用DIV做下拉列表
例题二.用div做下拉列表 <title>无标题文档</title> <style type="text/css"> *{ margin:0px ...
- VclZip压缩文件夹
压缩指定路径MyZipDir下的文件夹b及b目录下的所有文件和文件b.txt function ZipDir(zipMode:Integer;zipControl:TVCLZip;MyZipName, ...
- 为什么可以用while(cin)?
为什么可以用while(cin)? /** * @brief The quick-and-easy status check. * * This allows you to write const ...
- windows命令关机
不知道为啥,远程连接的window服务器没有关机命令,感觉是不是管理员权限导致的,所以找了下用命令关机,如下 shutdown -s -t #5秒内关机 shutdown -r -t #5秒内重启
- tomcat 无法加载js和css 等静态文件的问题
前段时间做了个网站,在本地tomcat测试都没有问题,但是部署到阿里云上之后,系统样式全没了.jsp等动态页面访问正常. 打开浏览器监控发现所有的css 和js 文件返回都是404 .直接访问单个的c ...
- tamper参数
"tamper/apostrophemask.py","tamper/equaltolike.py","tamper/greatest.py" ...
- jquery取消选择select下拉框
有三个select下拉框一个大类,两个小类隐藏,需要在选择大类的时候,小类显示同时清除另外的小类选择的项这需求有点儿.......... 下面是三个select: <select name=&q ...
- spring InitializingBean接口
最近工作需要得到sping中的每个事物需要执行的sql,称机会简单研究了一下spring的事务,项目中管理事务比较简单,用TransactionTemplate,就直接以TransactionTemp ...
- 工作中一个简单的shell程序
下面是工作中用到的链接数据库的shell程序. #!/bin/bash ] ; then echo "prase is wrong ,please check first" exi ...