Selecting Courses
64-bit integer IO format: %lld Java class name: Main
There are 12 classes every day, and 7 days every week. There are hundreds of courses in the college, and teaching a course needs one class each week. To give students more convenience, though teaching a course needs only one class, a course will be taught several times in a week. For example, a course may be taught both at the 7-th class on Tuesday and 12-th class on Wednesday, you should assume that there is no difference between the two classes, and that students can select any class to go. At the different weeks, a student can even go to different class as his wish. Because there are so many courses in the college, selecting courses is not an easy job for Li Ming. As his good friends, can you help him?
Input
Output
Sample Input
5 1 1 1 2 1 1 2 2 1 2 2 2 3 2 3 3 1 3 3
Sample Output
4
Source
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn = 310; 6 bool e[maxn][maxn],used[maxn]; 7 int Link[maxn],m,n; 8 bool match(int u){ 9 for(int i = 0; i < maxn; ++i){ 10 if(e[u][i] && !used[i]){ 11 used[i] = true; 12 if(Link[i] == -1 || match(Link[i])){ 13 Link[i] = u; 14 return true; 15 } 16 } 17 } 18 return false; 19 } 20 int main(){ 21 int x,y; 22 while(~scanf("%d",&n)){ 23 memset(e,false,sizeof e); 24 memset(Link,-1,sizeof Link); 25 for(int i = 1; i <= n; ++i){ 26 scanf("%d",&m); 27 while(m--){ 28 scanf("%d%d",&x,&y); 29 e[i][12*(x-1) + y] = true; 30 } 31 } 32 int ret = 0; 33 for(int i = 1; i <= n; ++i){ 34 memset(used,false,sizeof used); 35 if(match(i)) ++ret; 36 } 37 printf("%d\n",ret); 38 } 39 return 0; 40 }