HDU 4292 Food

Source: Internet
Author: User

Foodtime limit:1000msmemory limit:32768kbthis problem'll be judged onHDU. Original id:4292
64-bit integer IO format: %i64d Java class name: Main You, a part-time dining service worker in your college ' s dining hall, is now confused with a new problem:serve as many p Eople as possible.
The issue comes up as people in your college is more and more difficult to serve with meal:they eat only some certain ki NDS of food and drink, and with requirement unsatisfied, go away directly.
You are prepared F (1 <= f <=) kinds of food and D (1 <= d <=) kinds of drink. Each of the kind of food or drink have certain amount, that's, how many people could the food or drink serve. Besides, you know there ' re N (1 <= N <= $) people and you too can tell people ' s personal preference for food and D Rink.
Back to your goal:to serve as many people as possible. So you must decide a plan where some people is served while requirements of the rest of them is unmet. You should notice this, when one's requirement is unmet, he/she would just go away, and refusing any service.
InputThere is 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 whethe R people I would 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 whethe R people I would accept drink J. "Y" for Yes and "N" for No.
Please process until EOF (End of File).
OutputFor each test case, maximum number of people to be satisfied. * Print a single line with one integer.
Sample Input
4 3 to 1 1 1YYNNYYYNYYNYYNYYYNYYNNNY
Sample Output
3
SourceACM/ICPC Asia Regional Chengdu Online Solution: Maximum flow, man split edge stream is 1
1#include <bits/stdc++.h>2 using namespacestd;3 Const intINF =0x3f3f3f3f;4 Const intMAXN =1010;5 structArc {6     intTo,flow,next;7Arcintx =0,inty =0,intz =-1) {8to =x;9Flow =y;TenNext =Z; One     } A} e[maxn*MAXN]; - inthead[maxn],cur[maxn],d[maxn],tot,s,t; - voidAddintUintVintflow) { theE[tot] =arc (V,flow,head[u]); -Head[u] = tot++; -E[tot] = arc (U,0, Head[v]); -HEAD[V] = tot++; + } -queue<int>Q; + BOOLBFs () { A      while(!q.empty ()) Q.pop (); atmemset (d,-1,sizeofd); - Q.push (S); -D[s] =1; -      while(!Q.empty ()) { -         intU =Q.front (); - Q.pop (); in          for(inti = Head[u]; ~i; i =E[i].next) { -             if(E[i].flow && d[e[i].to] = =-1) { toD[e[i].to] = D[u] +1; + Q.push (e[i].to); -             } the         } *     } $     returnD[t] >-1;Panax Notoginseng } - intDfsintUintLow ) { the     if(U = = T)returnLow ; +     intTMP =0, A; A      for(int&i = Cur[u]; ~i; i =E[i].next) { the         if(E[i].flow && d[u]+1==d[e[i].to]&& (a=Dfs (E[i].to,min (low,e[i].flow)))) { +Low-=A; -TMP + =A; $E[i].flow-=A; $e[i^1].flow + =A; -             if(!low) Break; -         } the     } -     if(!tmp) D[u] =-1;Wuyi     returntmp; the } - intDinic () { Wu     intRET =0; -      while(BFS ()) { Aboutmemcpy (Cur,head,sizeofcur); $RET + =DFS (s,inf); -     } -     returnret; - } A CharSTR[MAXN]; + intMain () { the     intN,f,d,flow; -      while(~SCANF ("%d%d%d",&n,&f,&D)) { $memset (head,-1,sizeofhead); theS = tot =0; theR +; the          for(inti =1; I <= F; ++i) { thescanf"%d",&flow); - Add (s,i,flow); in         } the          for(inti =1; I <= D; ++i) { thescanf"%d",&flow); AboutAdd (F +i,t,flow); the         } the          for(inti =1; I <= N; ++i) { theAdd (F + D + i*2-1, F + D + i*2,1); +scanf"%s", str); -              for(intj =0; STR[J]; ++j) the                 if(Str[j] = ='Y') Add (j+1, F + D + i*2-1, INF);Bayi         } the          for(inti =1; I <= N; ++i) { thescanf"%s", str); -              for(intj =0; STR[J]; ++j) -                 if(Str[j] = ='Y') Add (F + D + i*2, F + j +1, INF); the         } theprintf"%d\n", Dinic ()); the     } the     return 0; -}
View Code

HDU 4292 Food

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.