[BZOJ2879] [Noi2012] Food festival (fee flow & dynamic Plus)

Source: Internet
Author: User

Description

CZ City in order to welcome students all over the country, specially held a grand food festival. As a gourmet guest who likes early taste, little M is naturally reluctant to miss the feast. He soon tasted all the delicacies of the Gourmet festival. However, the desires of the early adopters are difficult to satisfy. Even though all the dishes were delicious and the cooks were quick to cook, little m still felt that there was no food on his table that had been placed on others ' tables as an intolerable thing. So small m began to study the problem of cooking order, that is, arrange a cooking order so that the students have the shortest waiting time. Small m found that the food Festival has a total of n different kinds of dishes. Every time you order a meal, each student can choose one of the dishes. There are a total of M cooks to make these dishes. When all the students ordered the meal, the food production task was assigned to each chef. Then each chef will start cooking at the same time. Cooks will make them in the order they are requested and can only produce one person at a time. In addition, small m also found another interesting thing: Although the M chef will make all the n vegetables, but for the same dish, the different cooks ' production time may not be the same. He will dish with 1, 2, ..., n sequentially numbered, cooks with 1, 2, ..., m sequentially numbered, the time of the first chef of the J cooks to make the vegetables is ti,j. Little M thinks: the waiting time for each classmate is the total length of time for all cooks to start cooking, to their own portion of the finished dish. In other words, if a classmate ordered a dish that was made by a chef, his waiting time was the sum of the time the chef cooked the K-course. The total waiting time is the sum of the waiting time for all the students. Now, small m found all the students a la carte information: There are PI students ordered the first I vegetable products (i=1, 2, ..., n). What he wants to know is what the minimum total waiting time is.

InputThe 1th line of the input file contains two positive integers n and m, indicating the number of dishes and the number of cooks. Line 2nd contains n positive integers, where number i is pi, which indicates the number of people who have vegetables in the first order. Then there are n rows, each containing m non-negative integers, and the number of J in line I of the n row is Ti,j, which indicates the time it takes for the chef to make the first I vegetable. Each line in the input file is separated by a space between two digits, and there are no extra spaces at the end of the line.
Output

The output contains only one line with an integer, which is the minimum value for the total wait time.

Sample Input
3 2
3 1 1
5 7
3 6
8 9
Sample Output47

"Sample description"
Chef 1 First make 1 dishes 2, then make 2 dishes 1. The waiting time for the 3 students who ordered the 3 courses was 3,3+5=8,3+5+5=13.
Chef 2 First make 1 dishes 1, then make 1 servings 3. The waiting time for the 2 students who ordered the 2 courses was 7,7+9=16. The
Total wait time is 3+8+13+7+16=47.
Although the dish 1 and the dish 3 are made faster by the chef 1, if these dishes are made by the Chef 1, the total waiting time is instead longer. If the above practice, the 1 dishes 1 and 1 dishes 3 adjusted to cook 2 made, so that the chef 2 will not idle, the total waiting time is shorter. The
can prove that there is no better ordering scheme.

"Data size and conventions"
for 100% of data, N <=, M <=, p <=, ti,j <= 1000 (where P =∑PI, the total number of students in a la carte).
The N, m, and P values for each group of data are as follows:
Test point number N m p
1 n = 5  m = 5 p = Ten
2  n =  m = 1 p = 5
3 n =   m = 2 p =
4 n =  m =  p = +
n = 5 m =  p = +
6 n =     m =  p = 7
N =  m =   ;   p = + 8 n =  m =  p = 9 N =  m =   p = + +
10   n =  m =   p = +
HINTSourceSolution

  And $bzoj1070$ is actually a problem, but this problem force dynamic plus edge, do not know why the first $2$ point will $tle$, in short $bzoj$ can $ac$

1#include <bits/stdc++.h>2 using namespacestd;3 structEdge4 {5     intu, V, W, c, NXT;6}e[80005];7 intN, fst[1005], t[ $][ the], Etot =1, level[1005];8 intq[1005], belong[1005], fin[ the], pth[1005], use;9 BOOLinq[1005];Ten    One voidAddedge (intUintVintWintc) A { -E[++etot] = (edge) {u, V, W, C, Fst[u]}, fst[u] =Etot; -E[++etot] = (edge) {V, U,0,-C, Fst[v]}, fst[v] =Etot; the } -    - BOOLSPFA () - { +     intFront =0, back, U; -Memset (Level, the,sizeof(level)); +Level[n +1] =0; AQ[back =1] = n +1, Inq[n +1] =true; at      while(Front! =Back ) -     { -U = q[(++front%1005)]; -Front%=1005, Inq[u] =false; -          for(inti = Fst[u]; I i =e[i].nxt) -             if(E[I].W && LEVEL[E[I].V] > Level[u] +e[i].c) in             { -LEVEL[E[I].V] = Level[u] +e[i].c; toPTH[E[I].V] =i; +                 if(!INQ[E[I].V]) -                 { theq[(++back%1005)] =e[i].v; *Back%=1005, INQ[E[I].V] =true; $                 }Panax Notoginseng             } -     } the     returnLevel[n +2] <1000000000; + } A    the intEdmond_karp () + { -      for(inti = Pth[n +2]; I i =pth[e[i].u]) $     { $--E[I].W, ++e[i ^1].W; -         if(E[i].u = = n +1) Use =e[i].v; -     } the     returnLevel[n +2]; - }Wuyi    the intMain () - { Wu     intM, tmp, ans =0, Ptot; -scanf"%d%d", &n, &m); About      for(inti =1; I <= N; ++i) $     { -scanf"%d", &tmp); -Addedge (i, n +2Tmp0); -     } A      for(inti =1; I <= N; ++i) +          for(intj =1; J <= M; ++j) thescanf"%d", &t[i][j]); -Ptot = n +2; $      for(inti =1; I <= m; ++i) the     { theBelong[++ptot] = i, + +Fin[i]; the          for(intj =1; J <= N; ++j) theAddedge (Ptot, J,1, T[j][i]); -Addedge (n +1, Ptot,1,0); in     } the      while(SPFA ()) the     { AboutAns + =Edmond_karp (); theTMP = Belong[++ptot] = Belong[use], + +fin[tmp]; the          for(inti =1; I <= N; ++i) theAddedge (Ptot, I,1, T[i][tmp] *fin[tmp]); +Addedge (n +1, Ptot,1,0); -     } theprintf"%d\n", ans);Bayi     return 0; the}
View Code

[BZOJ2879] [Noi2012] Food festival (fee flow & dynamic Plus)

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.