hdu 1528+hdu 1962(最小覆盖)
来源:互联网 发布:sql的insert语句 编辑:程序博客网 时间:2024/05/20 18:47
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1528
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1962
思路:求二分图的最小覆盖,最小覆盖=最大匹配;
建图略麻烦。。。
View Code
1 #include<iostream> 2 const int MAXN=30; 3 using namespace std; 4 int n; 5 bool map[MAXN][MAXN]; 6 int lx[MAXN],ly[MAXN]; 7 bool mark[MAXN]; 8 9 int dfs(int u){10 for(int i=1;i<=n;i++){11 if(!mark[i]&&map[u][i]){12 mark[i]=true;13 if(ly[i]==-1||dfs(ly[i])){14 ly[i]=u;15 lx[u]=i;16 return true;17 }18 }19 }20 return false;21 }22 23 int MaxMatch(){24 int res=0;25 memset(lx,-1,sizeof(lx));26 memset(ly,-1,sizeof(ly));27 for(int i=1;i<=n;i++){28 if(lx[i]==-1){29 memset(mark,false,sizeof(mark));30 res+=dfs(i);31 }32 }33 return res;34 }35 36 int main(){37 int _case;38 scanf("%d",&_case);39 while(_case--){40 scanf("%d",&n);41 char str1[MAXN][4],str2[MAXN][4];42 memset(map,false,sizeof(map));43 for(int i=1;i<=n;i++){44 scanf("%s",str1[i]);45 }46 for(int i=1;i<=n;i++){47 scanf("%s",str2[i]);48 for(int j=1;j<=n;j++){49 if(str2[i][0]==str1[j][0]){50 if(str2[i][1]==str1[j][1])continue;51 else if(str2[i][1]=='H'){52 map[i][j]=true;53 }else if(str2[i][1]=='S'&&str1[j][1]!='H'){54 map[i][j]=true;55 }else if(str2[i][1]=='D'&&str1[j][1]=='C'){56 map[i][j]=true;57 }58 }else if(str2[i][0]>='2'&&str2[i][0]<='9'){59 if(str1[j][0]>='2'&&str1[j][0]<='9'&&str2[i][0]>str1[j][0]){60 map[i][j]=true;61 }62 }else if(str2[i][0]=='T'&&str1[j][0]>='2'&&str1[j][0]<='9'){63 map[i][j]=true;64 }else if(str2[i][0]=='J'&&(str1[j][0]>='2'&&str1[j][0]<='9'||str1[j][0]=='T')){65 map[i][j]=true;66 }else if(str2[i][0]=='Q'&&str1[j][0]!='K'&&str1[j][0]!='A'){67 map[i][j]=true;68 }else if(str2[i][0]=='K'&&str1[j][0]!='A'){69 map[i][j]=true;70 }else if(str2[i][0]=='A'){71 map[i][j]=true;72 }73 }74 }75 int ans=MaxMatch();76 printf("%d\n",ans);77 }78 return 0;79 }
0 0
- hdu 1528+hdu 1962(最小覆盖)
- hdu 3360(最小覆盖)
- hdu 1528 Card Game Cheater (最小覆盖)
- hdu 1528 Card Game Cheater (最小覆盖)
- hdu 1528 Card Game Cheater(最小覆盖)
- HDU 1350(最小路径覆盖)
- hdu 3991(最小路径覆盖)
- hdu 1150 Machine Schedule (最小覆盖)
- hdu 2119 Matrix (最小覆盖)
- hdu 3335 (最小路径覆盖)
- hdu 1498 (最小顶点覆盖)
- hdu 1054(最小顶点覆盖)
- hdu 3335(最小路径覆盖)
- hdu 4160(最小路径覆盖)
- hdu 1150(最小点覆盖)
- hdu 1350+hdu 1960(最小路径覆盖)
- HDU 1054 最小顶点覆盖
- HDU 1054 最小顶点覆盖
- 硬盘检测 - smartctl
- hdu 1712(分组背包)
- Dubbo zookeeper 初探(2)
- hdu 1054(最小顶点覆盖)
- hdu 1068(最大独立集)
- hdu 1528+hdu 1962(最小覆盖)
- hdu 1420(快速幂)
- hdu 1075(字典树)
- hdu 1247(Trie)
- hdu 1426(九宫格)
- hdu 3999(二叉排序树)
- hdu 3732(01背包转多重背包)
- hdu 3709+hdu 3555(数位dp)
- hdu 1224(最长路)