bzoj3144

Posted 123456

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bzoj3144相关的知识,希望对你有一定的参考价值。

最小割

问题就在于如何限制<=D

http://blog.csdn.net/zarxdy34/article/details/45272055

只要仔细看看那个图就懂了

技术分享图片
#include<bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
const int N = 41 * 41 * 41, inf = 1e9;
int rd()
{
    int x = 0, f = 1; char c = getchar();
    while(c < 0 || c > 9) { if(c == -) f = -1; c = getchar(); }
    while(c >= 0 && c <= 9) { x = x * 10 + c - 0; c = getchar(); }
    return x * f;
}
int n, m, k, D, source, sink, cnt = 1, tot;
int a[N], d[N], head[N], iter[N], id[41][41][41];
struct edge {
    int nxt, to, f;
} e[N * 5];
bool bfs()
{
    queue<int> q;
    memset(d, -1, sizeof(d));
    d[source] = 0;
    q.push(source);
    while(!q.empty())
    {
        int u = q.front();
        q.pop();
        for(int i = head[u]; i; i = e[i].nxt) if(d[e[i].to] == -1 && e[i].f) 
        {
            d[e[i].to] = d[u] + 1;
            q.push(e[i].to);
        }
    }
    return d[sink] != -1;
}
int dfs(int u, int delta)
{
    if(u == sink) return delta;
    int ret = 0;
    for(int &i = iter[u]; i && delta; i = e[i].nxt) if(d[e[i].to] == d[u] + 1 && e[i].f)
    {
        int x = dfs(e[i].to, min(delta, e[i].f));
        ret += x;
        delta -= x;
        e[i].f -= x;
        e[i ^ 1].f += x;    
    }
    return ret;
}
int dinic() 
{
    int ret = 0;
    while(bfs())
    {
        for(int i = source; i <= sink; ++i) iter[i] = head[i];
        ret += dfs(source, inf);
    }
    return ret;
}
void link(int u, int v, int f)
{
    e[++cnt].nxt = head[u];
    head[u] = cnt;
    e[cnt].to = v;
    e[cnt].f = f;
}
void insert(int u, int v, int f)
{
    link(u, v, f);
    link(v, u, 0);
}
int main()
{
    scanf("%d%d%d%d", &n, &m, &k, &D);
    sink = n * m * (k + 2) + 1;
    for(int x = 1; x <= n; ++x)
        for(int y = 1; y <= m; ++y)
            for(int z = 1; z <= k + 1; ++z)
                id[x][y][z] = ++tot;
    sink = ++tot;
    for(int z = 1; z <= k; ++z) 
        for(int x = 1; x <= n; ++x)
            for(int y = 1; y <= m; ++y) 
            {
                int v;
                scanf("%d", &v);
                insert(id[x][y][z], id[x][y][z + 1], v);
                for(int i = 0; i < 4; ++i) 
                {
                    int xx = x + dx[i], yy = y + dy[i];
                    if(xx > 0 && xx <= n && yy > 0 && yy <= m) 
                        if(z - 1 - D > 0) insert(id[x][y][z], id[xx][yy][z - D], inf);
                }
            }
    for(int x = 1; x <= n; ++x)
        for(int y = 1; y <= m; ++y) 
        {
            insert(source, id[x][y][1], inf);
            insert(id[x][y][k + 1], sink, inf);
        }
    printf("%d\n", dinic());
    return 0;
}
View Code

 

以上是关于bzoj3144的主要内容,如果未能解决你的问题,请参考以下文章

bzoj3144HNOI2013切糕

bzoj千题计划142:bzoj3144: [Hnoi2013]切糕

bzoj 3144(ACM恢复训练)

bzoj3144

BZOJ 3144: [Hnoi2013]切糕

BZOJ3144 切糕