BZOJ1391: [Ceoi2008]order

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   ar   for   

1391: [Ceoi2008]orderTime Limit: 10 Sec  Memory Limit: 64 MB
Submit: 534  Solved: 170
[Submit][Status]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
110Sample Output50HINT

Source

題解:

一直在糾結怎麼解決當租用機器的錢超過購買機器的錢的時候選擇購買,想了想最大權閉合子圖,發現不對,費用流,還是無果。

結果一看題解,瞬間石化了。

源點向每個任務連流量為任務權值的邊、任務向機器連租金的邊、、機器向匯點連售價的邊、、 答案為、任務利潤和-最大流、、
這個最大流實際上跑的是最小費用,為什嗎?還待思考。。。
。。。。。。。。。。。。。。
我的腦洞好大。。。。。。。。
連續提交7次都是WA,實在受不了了叫了hzwer大大的代碼。。。
代碼:
 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #define inf 0x7fffffff 5 using namespace std; 6 int T,n,m,cnt=1,ans,cur[2501],q[2505],head[2505],h[2505]; 7 struct data{int to,next,v;}e[3000001]; 8 void ins(int u,int v,int w) 9 {cnt++;e[cnt].to=v;e[cnt].v=w;e[cnt].next=head[u];head[u]=cnt;}10 void insert(int u,int v,int w)11 {ins(u,v,w);ins(v,u,0);}12 bool bfs()13 {14      int t=0,w=1,i,now;15      for(int i=1;i<=T;i++)h[i]=-1;16      q[0]=h[0]=0;17      while(t!=w)18      {19             now=q[t];t++;if(t==2501)t=0;20             for(i=head[now];i;i=e[i].next)21             {22                   if(e[i].v&&h[e[i].to]<0)23                         {h[e[i].to]=h[now]+1;q[w++]=e[i].to;if(w==2501)w=0;}24              }25      }26      if(h[T]==-1)return 0;return 1;27      }28 int dfs(int x,int f)29 {30     if(x==T)return f;31     int w,used=0;32     for(int i=cur[x];i;i=e[i].next)33     {34             if(e[i].v&&h[e[i].to]==h[x]+1)35             {36                 w=f-used;37                 w=dfs(e[i].to,min(w,e[i].v));  38                 e[i].v-=w;if(e[i].v>0)cur[x]=i;e[i^1].v+=w;39                 used+=w;if(used==f)return f;                     40                 }41             }42     if(!used)h[x]=-1;43     return used;44     }45 void dinic(){while(bfs()){for(int i=0;i<=T;i++)cur[i]=head[i];ans-=dfs(0,inf);}}46 int main()47 {48     scanf("%d%d",&n,&m);49     T=n+m+1;50     int a,b,c,d;51     for(int i=1;i<=n;i++)52     {53         scanf("%d%d",&a,&b);54         insert(0,i,a);ans+=a;55         for(int j=1;j<=b;j++)56         {57             scanf("%d%d",&c,&d);58             insert(i,n+c,d);59         }60     }61     for(int i=1;i<=m;i++)62     {63         scanf("%d",&a);64         insert(n+i,T,a);65     }66     dinic();67     printf("%d",ans);68     return 0;69 }
View Code

 

BZOJ1391: [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.