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;
}

BZOJ4439——[Swerc2015]Landscaping的更多相关文章

  1. 【BZOJ4439】[Swerc2015]Landscaping 最小割

    [BZOJ4439][Swerc2015]Landscaping Description FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地从左到右 ...

  2. bzoj 4439: [Swerc2015]Landscaping -- 最小割

    4439: [Swerc2015]Landscaping Time Limit: 2 Sec  Memory Limit: 512 MB Description FJ有一块N*M的矩形田地,有两种地形 ...

  3. 【bzoj4439】[Swerc2015]Landscaping 网络流最小割

    题目描述 FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地从左到右完整开收割机走到头,再对每一列从上到下完整走到头,如下图所示 对于一个4*4的田 ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. BZOJ_4439_[Swerc2015]Landscaping_最小割

    BZOJ_4439_[Swerc2015]Landscaping_最小割 Description FJ有一块N*M的矩形田地,有两种地形高地(用‘#’表示)和低地(用‘.’表示) FJ需要对每一行田地 ...

  6. 解决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. ...

  7. Landscaping Gym - 101128F (网络流)

    Problem F: Landscaping \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 题意是给出一个\(n*m\)的格子,其中一些是低 ...

  8. POJ 2433 Landscaping (贪心)

    题意:给定一个序列表示一群山,要你保留最多 K 个山峰,最少要削去多少体积和土.一个山峰是指一段连续的相等的区间,并且左边和右边只能比这个区间低,或者是边界. 析:贪心,每次都寻找体积最小的山峰,然后 ...

  9. LA 7277 Landscaping(最小割)

    https://vjudge.net/problem/UVALive-7277 题意: 给出一个n*m的地图,.代表低坡,#代表高坡. 现在有n+m辆车分别从上端和左端出发,如果在行驶的过程中需要转换 ...

随机推荐

  1. gnuplot conditional plotting: plot col A:col B if col C == x

    http://stackoverflow.com/questions/6564561/gnuplot-conditional-plotting-plot-col-acol-b-if-col-c-x H ...

  2. bootstrap弹框

    http://v3.bootcss.com/javascript/#modals 参考bootstrap官网 模态框做php后端 前端一直不行,但是很多时候 用到ajax都要用到弹框,一直在代码里面找 ...

  3. 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【二】——使用Repository模式构建数据库访问层

    系列导航地址http://www.cnblogs.com/fzrain/p/3490137.html 前言 在数据访问层应用Repository模式来隔离对领域对象的细节操作是很有意义的.它位于映射层 ...

  4. C++ Reflection

    http://www.vollmann.com/en/pubs/meta/meta/meta.html http://www.extreme.indiana.edu/reflcpp/ http://w ...

  5. 几个有用的JavaScript/jQuery代码片段(转)

    1. 检查数据是否包含在Array中 //jQuery实现 jQuery.inArray("value", arr); // 使用方法: if( jQuery.inArray(&q ...

  6. array_map与array_column之间的关系

    /*|----------------------------------------------------------|array_map();将回调函数作用到给定数组的单元上|array_col ...

  7. Task异常处理

    http://www.cnblogs.com/xray2005/archive/2011/08/24/2151459.html

  8. jquery mobile常用的data-role类型 data-icon data-iconpos

    文章链接: http://blog.csdn.net/cainiaoxiaozhou/article/details/48521241

  9. git执行pull命令时,报错

    在图形界面中,执行拉取操作时,出现下面的错误. You asked to pull from the remote 'origin', but did not specifya branch. Bec ...

  10. hdu4915 Parenthese sequence 贪心O(n)解法(new)

    hdu4915 Parenthese sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K ...