Hdu3.pdf (maximum incoming door template)

Source: Internet
Author: User

 

Roller coaster Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 9322 Accepted Submission (s): 4108



Problem Description RPG girls went to the playground today and finally got on the coveted roller coaster. However, there are only two seats in each row of the roller coaster, and there is an unwritten rule, that is, every girl must find a boy as a partner and sit with her. However, every girl has her own ideas. For example, Rabbit is only willing to be a partner with XHD or PQK. Grass is only willing to be a partner with linle or LL, princessSnow is willing to be a partner with the water prodigal son or pseudo cool. Considering the funding issue, boss Liu decided to let the partner find a ride on the roller coaster. Other people, hey, just stand and watch it. Smart Acmer, can you help calculate how many combinations can ride on a roller coaster?
The first line of Input data is a three integer K, M, N, indicating the number of possible combinations, the number of girls, and the number of boys. 0 1 <= N and M <= 500. In the next K rows, each row has two numbers, indicating that female Ai is willing to be partner with boys' Bj. The last 0 end input.
Output outputs an integer for each group of data, indicating the maximum number of combinations that can be used on a roller coaster.
Sample Input
6 3 31 11 21 32 12 33 10

Sample Output
3

Author PrincessSnow
Source RPG exercise session
Recommend lcy | We have carefully selected several similar problems for you: 1068 1083 2444 1281

 

Recently, I have been looking at Graph Theory (mainly because I was barely touched before... It's too scum ...) A template question, not explained

 

Common

 

// Maximum stream common algorithm # include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
       
Using namespace std; const int MAX = 1010; const int INF = 1 <30; struct edge {int to, cap, rev ;}; vector
       
         G [MAX]; bool used [MAX]; void add (int from, int to, int cap) {G [from]. push_back (edge) {to, cap, G [to]. size ()}); G [to]. push_back (edge) {from, 0, G [from]. size ()-1});} int dfs (int v, int t, int f) {if (v = t) return f; used [v] = true; for (int I = 0; I
        
          0) {int d = dfs (e. to, t, min (f, e. cap); if (d> 0) {e. cap-= d; G [e. to] [e. rev]. cap + = d; return d ;}}return 0 ;}int max_flow (int s, int t) {int flow = 0; for (;) {memset (used, 0, sizeof (used); int f = dfs (s, t, INF); if (f = 0) return flow; flow + = f ;}} int main () {int T; while (cin> T) {for (int kase = 1; kase <= T; kase ++) {for (int I = 0; I
         
           > N> m; for (int I = 0; I
          
            Bfs is used for optimization (although this question is obviously unnecessary ):
           

 

 

#include
            
             #include#include
             
              #include
              
               #include
               
                #include
                
                 using namespace std;const int MAX=1010;const int INF=1<<30;struct edge{int to,cap,rev;};vector
                 
                   G[MAX];int level[MAX];int iter[MAX];void add(int from,int to,int cap){ G[from].push_back((edge){to,cap,G[to].size()}); G[to].push_back((edge){from,0,G[from].size()-1});}void bfs(int s){ memset(level,-1,sizeof(level)); queue
                  
                    que; level[s]=0; que.push(s); while(!que.empty()) { int v=que.front(); que.pop(); for(int i=0;i
                   
                    0&& level[e.to]<0) { level[e.to]=level[v]+1; que.push(e.to); } } }}int dfs(int v,int t,int f){ if(v==t) return f; for(int &i=iter[v];i
                    
                     0&&level[v]
                     
                      0) { e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0;}int max_flow(int s,int t){ int flow=0; for(;;) { bfs(s); if(level[t]<0) return flow; memset(iter,0,sizeof(iter)); int f; while((f=dfs(s,t,INF))>0) flow+=f; }}int main(){ int T; while(cin>>T) { for(int kase=1;kase<=T;kase++) { for(int i=0;i
                      
                       >n>>m; for(int i=0;i
                       
                        

 

 

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.