[POJ] 2239 Selecting Courses (two-figure maximum match)

Source: Internet
Author: User
Tags ming

Title Address: http://poj.org/problem?id=2239

Li Ming University elective courses, 12 lessons per day, 7 days a week, each of the same classes may have multiple sections distributed in different days of different sections. Ask Li Ming to choose the maximum number of lessons. Divide n classes into x sets, dividing the 84 lessons of a week into Y-sets,

From Xi to Yi Lian Bian, then converted into a binary graph to find the maximum number of matches, and then the Hungarian algorithm can be.

1#include <cstdio>2#include <iostream>3#include <string.h>4#include <algorithm>5#include <math.h>6#include <stdbool.h>7#include <time.h>8#include <stdlib.h>9#include <Set>Ten#include <map> One#include <stack> A#include <queue> -#include <vector> - using namespacestd; the #defineCLR (x, y) memset (x,y,sizeof (×)) - #defineSQR (x) ((x) * (x)) - #defineRep (i,a,b) for (int i= (a); i<= (b); i++) - #defineLL Long Long + #defineINF 0x3f3f3f3f - #defineA First + #defineB Second A #definePI ACOs (-1.0) at Const intn= -+131; - intN,f[n],g[n][n],link[n]; -  - voidInit () - { -CLR (F,0); inCLR (g,0); -CLR (link,-1); to } +  - BOOLFindintx) the { *      for(intI=1; i<= -; i++) { $         if(!f[i] &&G[x][i]) {Panax Notoginsengf[i]=1; -             if(link[i]==-1||find (Link[i])) { thelink[i]=x; +                 return true; A             } the         } +     } -      $     return false; $ } -  - intHungary () the { -     intans=0;Wuyi      for(intI=1; i<=n;i++) { theCLR (F,0); -         if(Find (i)) ans++; Wu     } -     returnans; About } $  - intMain () - { -     intu,v,k; A      +      while(~SCANF ("%d",&N)) { the init (); -          for(intI=1; i<=n;i++) { $scanf"%d",&k); the              for(intj=1; j<=k;j++) { thescanf"%d%d",&u,&v); theg[i][(U1)* A+v]=1; the             } -         } inprintf"%d\n", Hungary ()); the     } the      About      the     return 0; the}

[POJ] 2239 Selecting Courses (two-figure maximum match)

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.