最佳派对
Time Limit:1000MS Memory Limit:65536K
Total Submit:90 Accepted:48
Description
国际学生夏令营在北京举行,经过一段时间的活动与交流,同学们逐渐相互了解。组委会决定举行一项派对表演活动,每对由一名中国学生与外国学生组成,要求每对的2位同学在表演技能和语言上能互相配合。在众多的同学中,每一位外国同学都可以与其他若干个中国同学很好地配合。如何选择派对,使得能选出最多的派对。
对于给定的外国同学与中国同学的配合情况,编程找出一个最佳派对方案,使得能选出最多的派对。
Input
第1行的2个数是n和e。n是中国同学(n<100);e是同学们的配合数。
接下来e行中,每行有2个正整数i和j,表示外国同学i可以和中国同学j配合
Output
将求得的最多的派对数目M
如果所求的最佳派对方案不存在,则在输出文件写入'NO SOLUTION'。
Sample Input
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 1
4 2
5 3
Sample Output
5
Source
elba
-
#include<iostream> #include<cmath> #include<cstdio> #include <memory.h> using namespace std; int m,n,ans;bool a[101][101];int p[101];bool used[101]; int Input() { char c=getchar(); int n=0; while(c < '0' || c > '9') c=getchar(); while(c >= '0' && c <= '9') n=(n << 1)+(n << 3)+(c-48) , c=getchar(); return n; } bool find(int x) { int j; for(j=1;j<=n;j++) { if(a[x][j]&&!used[j]) { used[j]=true; if(p[j]==0||find(p[j])) { p[j]=x; return true; } } } return false; } int main() { n=Input(); int k=Input(); for(int i=1;i<=k;i++) { int h=Input(),r=Input(); a[h][r]=true; } for(int i=1;i<=n;i++) { memset(used,0,sizeof(used)); if(find(i))ans++; } if(ans>0)printf("%d",ans); else printf("NO SOLUTION"); }