Bzoj 2879 NOI2012 Food Festival fee flow

Source: Internet
Author: User

The main topic: given N-course and M-chef, the first-course dishes need p[i], the first J chef to do the I-dish takes time t[i][j], seeking the longest total waiting time

A chef's last-minute meal. The contribution to the answer is one time, and the penultimate dish contributes twice times more to the answer, and so on.

The Cooks are furious! Spell Card and Taboo "p re-exist"!

Divide each chef into σp[i] points, each dish to each chef's point I points a flow of 1, the cost of time I times, each point to the meeting point a flow of 1 of the cost of 0 of the side, run the minimum cost maximum flow

Can this run? No, t to die?

Dynamic add-on can

Each chef initially has only one point, and if the chef finishes the last dish, add a point that will ensure that the chef's points are O (p+m)

Damn it to death--an augmented road where only one chef cooks--all the rest--so find the first chef to add a little bit--this is the wrong card one afternoon

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 100100# Define S 0#define T 100099#define INF 0x3f3f3f3fusing namespace std;struct abcd{int to,flow,cost,next;} Table[1001001];int head[m],tot=1;int n,m,now,ans,a[50][110];int belong[m],cnt[m],cost[m];void Add (int x,int y,int Z, int W) {Table[++tot].to=y;table[tot].flow=z;table[tot].cost=w;table[tot].next=head[x];head[x]=tot;} void Link (int x,int y,int z,int w) {Add (x,y,z,w); ADD (y,x,0,-w);} BOOL Edmonds_karp () {static int q[65540],flow[m],from[m];static unsigned short r,h;static bool V[m];int i,j;memset (Cost, 0x3f,sizeof cost); Cost[s]=0;q[++r]=s;flow[s]=inf;flow[t]=0;//cost[t]=inf;while (r!=h) {int x=q[++h];v[x]=0;for (i= Head[x];i;i=table[i].next) if (Table[i].flow && cost[table[i].to]>cost[x]+table[i].cost) {cost[table[i]. To]=cost[x]+table[i].cost;flow[table[i].to]=min (Flow[x],table[i].flow); From[table[i].to]=i;if (!v[table[i].to]) v[table[i].to]=1,q[++r]=table[i].to;}} if (!flow[t])Return False;ans+=flow[t]*cost[t];int x=0;for (i=from[t];i;i=from[table[i^1].to]) {table[i].flow-=flow[t];table[i^ 1].flow+=flow[t];if (table[i].to<100000) x=belong[table[i].to];} Link (s,++now,1,0); for (j=1;j<=n;j++) Link (now,100000+j,1,a[j][x]* (cnt[x]+1)); Cnt[x]++;belong[now]=x;return true;} int main () {#ifndef online_judgefreopen ("2879.in", "R", stdin) freopen ("2879.out", "w", stdout); #endifint i,j,x;cin >>n>>m;for (i=1;i<=n;i++) {scanf ("%d", &x); Link (100000+i,t,x,0);} for (i=1;i<=n;i++) for (j=1;j<=m;j++) scanf ("%d", &a[i][j]), for (j=1;j<=m;j++) {Link (s,++now,1,0); for (i= 1;i<=n;i++) Link (Now,100000+i,1,a[i][j]); cnt[j]++;belong[now]=j;} memset (cost,0x3f,sizeof cost), while (Edmonds_karp ()); Cout<<ans<<endl;return 0;}


Bzoj 2879 NOI2012 Food Festival fee flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.