PKU_2239 Selecting Courses

构图的时候是课程序号(0..n-1)到课的节数((p-1)*12+q-1)

然后土土匹配就可以AC

http://acm.pku.edu.cn/JudgeOnline/problem?id=2239


  1. #include <iostream>
  2. using namespace std;
  3. #define N 1000
  4. bool map[N][N],visit[N];
  5. int n,m,match[N];
  6. bool dfs(int pre)
  7. {
  8.     for(int i=0;i<m;i++)
  9.     {
  10.         if(map[pre][i]&&!visit[i])
  11.         {
  12.             visit[i]=true;
  13.             int t=match[i];
  14.             match[i]=pre;
  15.             if(t==-1||dfs(t)) return true;
  16.             match[i]=t;
  17.         }
  18.     }
  19.     return false;
  20. }
  21. int find_match()
  22. {
  23.     memset(match,-1,sizeof(match));
  24.     int i,sum=0;
  25.     for(i=0;i<n;i++){memset(visit,false,sizeof(visit));if(dfs(i)) sum++;}
  26.     return sum;
  27. }
  28. int main()
  29. {
  30.     int i,j,x,y,t;
  31.     while(scanf("%d",&n)!=EOF)
  32.         {
  33.             memset(map,false,sizeof(map));
  34.             m=84;
  35.             for(i=0;i<n;i++)
  36.             {
  37.                 scanf("%d",&j);
  38.                 while(j--)scanf("%d%d",&x,&y),map[i][(x-1)*12+y-1]=true;
  39.             }
  40.             cout<<find_match()<<endl;
  41.         }
  42. }

你可能感兴趣的:(ini)