hdu 1528+hdu 1962(最小覆盖)
2013-04-04 21:54
330 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1528
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1962
思路:求二分图的最小覆盖,最小覆盖=最大匹配;
建图略麻烦。。。
View Code
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1962
思路:求二分图的最小覆盖,最小覆盖=最大匹配;
建图略麻烦。。。
View Code
#include<iostream> const int MAXN=30; using namespace std; int n; bool map[MAXN][MAXN]; int lx[MAXN],ly[MAXN]; bool mark[MAXN]; int dfs(int u){ for(int i=1;i<=n;i++){ if(!mark[i]&&map[u][i]){ mark[i]=true; if(ly[i]==-1||dfs(ly[i])){ ly[i]=u; lx[u]=i; return true; } } } return false; } int MaxMatch(){ int res=0; memset(lx,-1,sizeof(lx)); memset(ly,-1,sizeof(ly)); for(int i=1;i<=n;i++){ if(lx[i]==-1){ memset(mark,false,sizeof(mark)); res+=dfs(i); } } return res; } int main(){ int _case; scanf("%d",&_case); while(_case--){ scanf("%d",&n); char str1[MAXN][4],str2[MAXN][4]; memset(map,false,sizeof(map)); for(int i=1;i<=n;i++){ scanf("%s",str1[i]); } for(int i=1;i<=n;i++){ scanf("%s",str2[i]); for(int j=1;j<=n;j++){ if(str2[i][0]==str1[j][0]){ if(str2[i][1]==str1[j][1])continue; else if(str2[i][1]=='H'){ map[i][j]=true; }else if(str2[i][1]=='S'&&str1[j][1]!='H'){ map[i][j]=true; }else if(str2[i][1]=='D'&&str1[j][1]=='C'){ map[i][j]=true; } }else if(str2[i][0]>='2'&&str2[i][0]<='9'){ if(str1[j][0]>='2'&&str1[j][0]<='9'&&str2[i][0]>str1[j][0]){ map[i][j]=true; } }else if(str2[i][0]=='T'&&str1[j][0]>='2'&&str1[j][0]<='9'){ map[i][j]=true; }else if(str2[i][0]=='J'&&(str1[j][0]>='2'&&str1[j][0]<='9'||str1[j][0]=='T')){ map[i][j]=true; }else if(str2[i][0]=='Q'&&str1[j][0]!='K'&&str1[j][0]!='A'){ map[i][j]=true; }else if(str2[i][0]=='K'&&str1[j][0]!='A'){ map[i][j]=true; }else if(str2[i][0]=='A'){ map[i][j]=true; } } } int ans=MaxMatch(); printf("%d\n",ans); } return 0; }
相关文章推荐
- hdu 1528+hdu 1962(最小覆盖)
- HDU 1528 (二分图最大匹配 + 最小覆盖, 14.07.17)
- HDU1528-二分图最小点覆盖
- hdu 1528 Card Game Cheater (最小覆盖)
- hdu 1528 Card Game Cheater(最小覆盖)
- hdu 1528 Card Game Cheater (最小覆盖)
- hdu 1528 Card Game Cheater (最小覆盖)
- hdu1150匈牙利算法最小点覆盖
- hdu1054 二分图最小点覆盖与树形dp解法
- HDU 1151 Air Raid (最小路径覆盖入门级)
- hdu1350解题报告-最小边覆盖
- hdu 4606 Occupy Cities - 计算几何 + 最短路 + 最小路径覆盖
- HDU 3007 Realtime Status 最小圆覆盖
- HDU 3360 National Treasures(二分匹配,最小点覆盖)
- hdu1498 50 years, 50 colors --- 最小点覆盖
- HDU 1054 最小顶点覆盖 (树形dp)
- hdu 1151 Air Raid(二分图匹配--最小路径覆盖)
- HDU 1150 Machine Schedule (二分图最小点覆盖)
- hdu 1498 50 years, 50 colors 最小点覆盖
- HDU 1054 最小顶点覆盖