BZOJ4439——[Swerc2015]Landscaping
来源:互联网 发布:手板编程招聘 编辑:程序博客网 时间:2024/06/05 02:46
0、题目:
FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示)
FJ需要对每一行田地从左到右完整开收割机走到头,再对每一列从上到下完整走到头,如下图所示
对于一个4*4的田地,FJ需要走8次。
收割机是要油的,每次从高地到低地或从低地到高地需要支付A的费用。
但是FJ有黑科技,可以高地与低地的互变,都只需要一个支付B的费用。
询问FJ需要支付最小费用。
1、分析:这题考试的时候没有看懂,英语太垃圾了。。。。考完发现bzoj上有翻译QAQ
然后这就是个智障题了QAQ...我们对于所有的低处,从源点连一波长度是B的边
然后所有的高处,连一波边到汇点,长度是B。。。
然后对于相邻的点连一波边,边权是A,啊。。为啥低处要连向低处。。
原因就是最小割吗。。。需要确定S集和T集。。。
#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;}
0 0
- BZOJ4439——[Swerc2015]Landscaping
- 【BZOJ4439】[Swerc2015]Landscaping【最小割】
- Landscaping Gym
- poj 2433 Landscaping 贪心
- TOJ 3874: Landscaping -- DP
- POJ 2433 Landscaping
- BZOJ4586: [Usaco2016 Open]Landscaping
- bzoj4586: [Usaco2016 Open]Landscaping
- [BZOJ 4439] [swerc 2015] Landscaping
- 洛谷P3049 [USACO12MAR]园林绿化Landscaping
- GYM101128F.Landscaping(最小割-Dinic)
- bzoj 4586: [Usaco2016 Open]Landscaping 堆
- bzoj1749 [usaco2005 open]Landscaping 地形改造
- bzoj 1749: [usaco2005 open]Landscaping 地形改造
- GYM 101128 F.Landscaping【最小割--Dinic】
- GYM 101128 F.Landscaping(最小割-Dinic)
- Codeforces Gym 101128F (UVA Live 7277) Landscaping 最小割
- 【NOIP模拟题】【动态规划DP】2016.11.11第二题Landscaping题解
- VS2012配置OpenGL
- Coursera机器学习 week3 逻辑回归 编程作业代码
- C++实现设计模式之--单例模式
- linux下创建和删除软、硬链接
- margin重叠现象探讨研究
- BZOJ4439——[Swerc2015]Landscaping
- Mybatis中运用小技巧(二) like的使用
- javascript正则RegExp.test()需要注意:不具有可重入性
- 欢迎使用CSDN-markdown编辑器备份
- 带头双向循环链表的插入和删除
- Socket简单实例(简单实现调用accpet()方法开始监听)
- hash
- 字符串匹配的BM算法讲解(不含代码)
- python文本分类准备工作-扩展库的安装