BZOJ 1391: [Ceoi2008]order [最小割]

來源:互聯網
上載者:User

標籤:problem   blog   string   www   getch   ble   eof   多少   div   

1391: [Ceoi2008]orderTime Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1509  Solved: 460
[Submit][Status][Discuss]
Description有N個工作,M種機器,每種機器你可以租或者買過來. 每個工作包括若干道工序,每道工序需要某種機器來完成,你可以通過購買或租用機器來完成。 現在給出這些參數,求最大利潤Input第一行給出 N,M(1<=N<=1200,1<=M<=1200) 下面將有N塊資料,每塊資料第一行給出完成這個任務能賺到的錢(其在[1,5000])及有多少道工序 接下來若干行每行兩個數,分別描述完成工序所需要的機器編號及租用它的費用(其在[1,20000]) 最後M行,每行給出購買機器的費用(其在[1,20000])Output最大利潤Sample Input2 3
100 2
1 30
2 20
100 2
1 40
3 80
50
80
110
Sample Output50我靠這不最小割裸題收益,租用,買機器,必須放棄其中之一s--收益-->任務--租金-->機器--價錢-->t然後求最小割,再用總收益減就可以了
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int N=2405,M=2e6+5,INF=1e9;inline int read(){    char c=getchar();int x=0,f=1;    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 m,n,s,t,x,w,c,ans;struct edge{    int v,c,f,ne;}e[M<<1];int cnt,h[N];inline void ins(int u,int v,int c){    cnt++;    e[cnt].v=v;e[cnt].c=c;e[cnt].f=0;e[cnt].ne=h[u];h[u]=cnt;    cnt++;    e[cnt].v=u;e[cnt].c=0;e[cnt].f=0;e[cnt].ne=h[v];h[v]=cnt;}int q[N],head,tail,vis[N],d[N];bool bfs(){    memset(vis,0,sizeof(vis));    memset(d,0,sizeof(d));    head=tail=1;    d[s]=0;vis[s]=1;    q[tail++]=s;    while(head!=tail){        int u=q[head++];        for(int i=h[u];i;i=e[i].ne){            int v=e[i].v;            if(!vis[v]&&e[i].c>e[i].f){                vis[v]=1;                d[v]=d[u]+1;                q[tail++]=v;                if(v==t) return true;            }        }    }    return false;}int cur[N];int dfs(int u,int a){    if(u==t||a==0) return a;    int flow=0,f;    for(int &i=cur[u];i;i=e[i].ne){        int v=e[i].v;        if(d[v]==d[u]+1&&(f=dfs(v,min(a,e[i].c-e[i].f)))>0){            flow+=f;            e[i].f+=f;            e[((i-1)^1)+1].f-=f;            a-=f;            if(a==0) break;        }    }    return flow;}int dinic(){    int flow=0;    while(bfs()){        for(int i=s;i<=t;i++) cur[i]=h[i];        flow+=dfs(s,INF);    }    return flow;}int main(){    //freopen("in.txt","r",stdin);    n=read();m=read();s=0;t=n+m+1;    for(int i=1;i<=n;i++){        w=read();c=read();ans+=w;        ins(s,i,w);        while(c--) x=read(),w=read(),ins(i,n+x,w);    }    for(int i=1;i<=m;i++) w=read(),ins(n+i,t,w);    printf("%d",ans-dinic());}

 

  

BZOJ 1391: [Ceoi2008]order [最小割]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.