The King of "luogup1402" Hotel (Max Stream

Source: Internet
Author: User

Title Description

XX Hotel's boss wants to become the king of the hotel, in this hope, the first step to the hotel become humane. Since a lot of visitors to stay have their favorite room tones, sunshine, etc., but also have their own favorite dishes, but the hotel only p room, a day only fixed Q-channel different dishes.

A day came to n guests, each guest said he likes what room, like which dish. Unfortunately, it may not be possible to make all the customers happy (the condition is to live in a favorite room and eat a favorite dish).

How to allocate here, can make the most customer satisfaction?

Input/output format Input Format:

The first line gives three positive integers representing n,p,q (<=100).

After the n rows, the number of p in each row contains 0 or 1, the number of I indicates that I do not like the room I (1 likes, 0 means not like).

After n rows, the number of Q per line indicates that I do not like the I-dish.

output Format:

The largest number of customer satisfaction.

Input/Output sample Input Sample # #:Copy
2 2 21 01 01 11 1
Sample # # of output:Copy
1
Exercises

This is three times times the experience of the Tao.

@hongzy 2018-10-05 22:14 reply

The King of P1402 Hotel

P2891 [Usaco07open] eat Dining

The composition of P1231 teaching assistant

Three questions read in different,P1231 data range slightly larger, this is the difference.

To the person to break down, set as $x_1,x_2$.

From $s$ to each room, the capacity is $1$.

From each room to the $x_1$ that likes it, the capacity is $1$.

From each $x_1$ to the corresponding $x_2$ edge, the capacity is $1$. (Current limit

From each $x_2$ to his favorite dish, with a capacity of $1$.

Finally from each dish to $t$ Lian $1$, run maximum flow is the answer.

1 /*2 Qwerta3 the king of P1402 Hotel4 Accepted5  -6 Code C++,1.69KB7 Submission Time 2018-10-13 10:38:078 time consuming/memory9 34ms, 796KBTen */ One#include <iostream> A#include <cstring> -#include <cstdio> -#include <queue> the using namespacestd; - structemm{ -     inte,f,v; -}a[50003]; + inth[413]; - inttot=1; + voidConintXintYintDS) A { ata[++tot].f=H[x]; -h[x]=tot; -A[tot].e=y; -a[tot].v=ds; -a[++tot].f=H[y]; -h[y]=tot; inA[tot].e=x; -     return; to } +queue<int>que; - intd[413]; the ints,t; *InlineBOOLBFS () $ {Panax Notoginsengmemset (D,0,sizeof(d)); -d[s]=1; Que.push (s); the      while(!que.empty ()) +     { A         intx=Que.front (); Que.pop (); the          for(intI=h[x];i;i=a[i].f) +         if(!d[a[i].e]&&a[i].v) -         { $d[a[i].e]=d[x]+1; $ Que.push (A[I].E); -         } -     } the     returnD[t]; - }Wuyi intDfsintXintal) the { -     if(X==t| |! Alreturnal; Wu     intFl=0; -      for(intI=h[x];i;i=a[i].f) About     if(d[a[i].e]==d[x]+1&&a[i].v) $     { -         intf=Dfs (A[i].e,min (AL,A[I].V)); -         if(f) -         { Afl+=F; +al-=F; thea[i].v-=F; -a[i^1].v+=F; $             if(!al) Break; the         } the     } the     if(!FL) d[x]=-1; the     returnFL; - } in intMain () the { the     //freopen ("a.in", "R", stdin); About     intn,p,q; thescanf"%d%d%d",&n,&p,&q); thes=0, t=2*n+p+q+1; the      for(intI=1; i<=p;++i) +Con (s,i,1); -      for(intI=1; i<=n;++i) the     {Bayi          for(intj=1; j<=p;++j) the         { the             intx; -scanf"%d",&x); -             if(x) theCon (j,i+p,1); the         } the     } the      for(intI=1; i<=n;++i) -Con (i+p,i+p+n,1); the      for(intI=1; i<=n;++i) the     { the          for(intj=1; j<=q;++j)94         { the             intx; thescanf"%d",&x); the             if(x)98Con (i+p+n,j+p+n+n,1); About         } -     }101      for(intI=1; i<=q;++i)102Con (i+p+n+n,t,1);103     intans=0;104      while(BFS ())) Ans+=dfs (S,99999999); thecout<<ans;106     return 0;107}

The King of "luogup1402" Hotel (Max Stream

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.