HDU 4292 food 37th ACM/ICPC Chengdu division Network Competition 1005 question (maximum Stream)

Source: Internet
Author: User
Food

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 76 accepted submission (s): 47

Problem description you, a part-time dining service worker in your college's dining hall, are now confused with a new problem: serve as your people as possible.
The issue comes up as people in your college are more and more difficult to serve with meal: they eat only some certain kinds of food and drink, and with requirement unsatisfied, go away directly.
You have prepared F (1 <= F <= 200) kinds of food and D (1 <= d <= 200) kinds of drink. each kind of food or drink has certain amount, that is, how many people cocould this food or drink serve. besides, you know there're n (1 <= n <= 200) people and you too can tell people's personal preference for food and drink.
Back to your goal: to serve as your people as possible. so you must decide a plan where some people are served while requirements of the rest of them are unmet. you shoshould notice that, when one's requirement is unmet, he/she woshould just go away, refusing any service.

 

Input there are several test cases.
For each test case, the first line contains three numbers: N, F, D, denoting the number of people, food, and drink.
The second line contains F integers, the ith number of which denotes amount of representative food.
The third line contains d integers, the ith number of which denotes amount of representative drink.
Following is N line, each consisting of a string of length F. E jth character in the ith one of these lines denotes whether people I wowould accept food J. "Y" for yes and "N" for no.
Following is N line, each consisting of a string of length D. E jth character in the ith one of these lines denotes whether people I wowould accept drink J. "Y" for yes and "N" for no.
Please process until EOF (end of file ).

 

Output for each test case, please print a single line with one integer, the maximum number of people to be satisfied.

 

Sample input4 3 3 1 1 1 1 1 yyn nyy yny yyn NNY

 

Sample output3

 

Source2012 ACM/ICPC Asia Regional Chengdu online

 

Recommendliuyiding It is very bare and the biggest stream question. Similar to poj 3182. Use SAPAlgorithmIt does not time out and is more efficient.
# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Include <Iostream> Using   Namespace  STD; Const   Int Maxn = 11000  ;  Const   Int Maxm = 405000  ;  Const   Int INF = 0x3f3f3f  ;  Struct  Node {  Int   From , To, next;  Int  CAP;} edge [maxm];  Int  Tol;  Int  Head [maxn];  Int  Dep [maxn];  Int  Gap [maxn];  Int  N;  Void  Init () {Tol = 0 ; Memset (Head, - 1 , Sizeof  (Head ));}  Void Addedge ( Int U, Int V, Int  W) {edge [tol].  From = U; edge [tol]. = V; edge [tol]. Cap = W; edge [tol]. Next =Head [u]; head [u] = Tol ++ ; Edge [tol].  From = V; edge [tol]. = U; edge [tol]. Cap = 0  ; Edge [tol]. Next = Head [v]; head [v] = Tol ++ ;}  Void BFS ( Int Start, Int  End) {memset (DEP, -1 , Sizeof  (DEP); memset (gap,  0 , Sizeof  (GAP); Gap [  0 ] = 1  ;  Int  Que [maxn];  Int  Front, rear; front = Rear = 0  ; Dep [end] =0  ; Que [rear ++] = End;  While (Front! = Rear ){  Int U = que [Front ++ ];  If (Front = maxn) Front = 0  ;  For ( Int I = head [u]; I! =- 1 ; I = Edge [I]. Next ){ Int V = Edge [I].;  If (Edge [I]. Cap! = 0 | Dep [v]! =- 1 ) Continue  ; Que [rear ++] = V;  If (Rear> = maxn) rear = 0  ; Dep [v] = Dep [u] + 1  ; ++Gap [Dep [v] ;}}  Int SAP ( Int Start, Int  End ){  Int Res = 0  ; BFS (START, end );  Int  Cur [maxn];  Int  S [maxn];  Int Top = 0  ; Memcpy (cur, Head, Sizeof  (Head ));  Int U = Start;  Int  I;  While (DEP [start] < N ){  If (U = End ){  Int Temp = INF;  Int  Inser;  For (I = 0 ; I <top; I ++ )  If (Temp> Edge [s [I]. Cap) {temp = Edge [s [I]. CAP; inser = I ;}  For (I = 0 ; I <top; I ++ ) {Edge [s [I]. Cap -= Temp; edge [s [I] ^ 1 ]. Cap + =Temp;} res + = Temp; top = Inser; u = Edge [s [Top]. From  ;}  If (U! = End & gap [Dep [u]- 1 ] = 0 ) //  Fault occurred, no zengguang Road             Break  ;  For (I = cur [u]; I! =-1 ; I = Edge [I]. Next)  If (Edge [I]. Cap! = 0 & Amp; Dep [u] = Dep [edge [I]. To] + 1  )  Break  ;  If (I! =- 1  ) {Cur [u] = I; s [Top ++] = I; u =Edge [I]. ;}  Else  {  Int Min = N;  For (I = head [u]; I! =- 1 ; I = Edge [I]. Next ){  If (Edge [I]. Cap = 0 ) Continue  ;  If (Min>Dep [edge [I]. To]) {min = Dep [edge [I]. To]; cur [u] = I ;}} -- Gap [Dep [u]; Dep [u] = Min + 1  ; ++ Gap [Dep [u];  If (U! = Start) u = edge [s [-- top]. From  ;}}  Return  Res ;} Int G [ 2000 ] [ 2000  ];  Char STR [ 1200  ];  Int  Main (){  Int  Start, end;  Int  N, F, D;  Int  U;  Int I;  While (Scanf ( "  % D  " , & N, & F, & D )! = EOF) {memset (G,  0 , Sizeof  (G); Init (); n = F + D + 2 * N; Start = 0  ; End = N + 1 ;  For (I = 1 ; I <= f; I ++ ) {Scanf (  "  % D  " , & G [ 0  ] [I]); addedge (  0 , I, G [ 0  ] [I]);}  For (I = F + 2 * N + 1 ; I <= F + 2 * N + D; I ++ ) {Scanf (  "  % D  " ,& G [I] [end]); addedge (I, end, G [I] [end]);}  For (I = 1 ; I <= N; I ++ ) Addedge (F + 2 * I- 1 , F + 2 * I, 1 );  For (I = 1 ; I <= N; I ++ ) {Scanf (  "  % S  " ,& Str );  For ( Int J = 0 ; J <F; j ++ ){  If (STR [J] = ' Y  '  ) {Addedge (J + 1 , F + 2 * I- 1 , 1  );}}}  For (I = 1 ; I <= N; I ++ ) {Scanf (  "  % S  " ,&Str );  For ( Int J = 0 ; J <D; j ++ ){  If (STR [J] = '  Y  '  ) {Addedge (F + 2 * I, F + 2 * N + J + 1 , 1 ) ;}} Start = 0  ; End = N + 1  ; N + = 2  ; Printf (  "  % D \ n  "  , SAP (START, end ));}  Return   0  ;} 

 

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.