[BZOJ3144][HNOI2013]切糕 最小割__網路流

來源:互聯網
上載者:User

核心思想:在最小割中用容量為無窮大的邊來表示限制。
這題相當於一個 p∗q p*q的矩陣,每個矩陣添一個 [0,r] [0,r]的數,且相鄰數之差不超過 d d,同時最小化 v(i,j,k) v(i,j,k)。
先把一個格子的取值串起來,就是 (i,j,k) (i,j,k)向 (i,j,k+1) (i,j,k+1)連一條容量為 v(i,j,k+1) v(i,j,k+1)的邊;
特別地, S S向 (i,j,1) (i,j,1)連一條容量為 (i,j,1) (i,j,1)的邊, (i,j,r) (i,j,r)向T連一條容量為無窮大的邊;
那麼這些邊中必須割一條,表示填的數是什麼。
然後考慮差不超過d的限制,就是 (i,j,k) (i,j,k)向 (i−1,j,k−d) (i-1,j,k-d)、 (i+1,j,k−d) (i+1,j,k-d)、 (i,j−1,k−d) (i,j-1,k-d)、 (i,j+1,k−d) (i,j+1,k-d)連一條容量為無窮大的邊。
這樣就保證不能同時割 (i,j,≥k) (i,j,\ge k)和 (相鄰的,≤k−d) (相鄰的,\le k-d);因為每串最多割一條邊。
代碼:

#include<iostream>#include<cstdio>#include<cstring> #define G(x,y,z) (((x-1)*m+y-1)*r+z-1)using namespace std;int n,m,r,d,v[45][45][45],S,T,dl[64010],ne[64010];bool vis[64010];struct edge{    int t,c,f;    edge *next,*rev;}*con[64010];void ins(int x,int y,int c){    edge *p=new edge;p->t=y;p->c=c;p->f=0;p->next=con[x];con[x]=p;    p=new edge;p->t=x;p->c=0;p->f=0;p->next=con[y];con[y]=p;    con[x]->rev=con[y];con[y]->rev=con[x];}bool bfs(){    bool re=0;    memset(ne,0,sizeof(ne));    ne[S]=1;dl[1]=S;    for(int head=1,tail=1;head<=tail;head++)    {        int v=dl[head];        if(v==T) re=1;        for(edge *p=con[v];p;p=p->next)            if(p->c>p->f&&ne[p->t]==0)                ne[p->t]=ne[v]+1,dl[++tail]=p->t;    }    return re;}int dinic(int v,int fl

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.