继续匈牙利水题。。。 给你课程以及上课时间,问你一周最多可以选多少次课。每节课最多只能上一次。 建图很简单,课程和每周的第几节课建图,WA了一次, = = 一天12节我想成一天7节了,笨。。。 #include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> #define MAX 305 using namespace std; int map[MAX][MAX]; int used[MAX]; int match[MAX]; int n; int Augement(int n,int x) { int i; for(i=1; i<=n; i++) if( !used[i] && map[x][i] ) { used[i] = 1; if( match[i] == 0 || Augement(n,match[i]) ) { match[i] = x; return 1; } } return 0; } int Hungary(int n) { int i,sum = 0; memset(match,0,sizeof(match)); for(i=1; i<=n; i++) { memset(used,0,sizeof(used)); if( Augement(n,i) ) sum++; } return sum; } int main() { int i,m,day,t,ans; while( ~scanf("%d",&n) ) { memset(map,0,sizeof(map)); for(i=1; i<=n; i++) { scanf("%d",&m); while( m-- ) { scanf("%d%d",&day,&t); map[i][(day-1)*12+t] = 1; } } ans = Hungary(max(n,84)); printf("%d/n",ans); } return 0; }