HDU 3395 Special Fish 二分匹配(求最大匹配值)
2013-08-06 17:17
246 查看
点击打开链接
Total Submission(s): 1111 Accepted Submission(s): 422
[align=left]Problem Description[/align]
There is a kind of special fish in the East Lake where is closed to campus of Wuhan University. It’s hard to say which gender of those fish are, because every fish believes itself as a male, and it may attack one of some other fish
who is believed to be female by it.
A fish will spawn after it has been attacked. Each fish can attack one other fish and can only be attacked once. No matter a fish is attacked or not, it can still try to attack another fish which is believed to be female by it.
There is a value we assigned to each fish and the spawns that two fish spawned also have a value which can be calculated by XOR operator through the value of its parents.
We want to know the maximum possibility of the sum of the spawns.
[align=left]Input[/align]
The input consists of multiply test cases. The first line of each test case contains an integer n (0 < n <= 100), which is the number of the fish. The next line consists of n integers, indicating the value (0 < value <= 100) of each
fish. The next n lines, each line contains n integers, represent a 01 matrix. The i-th fish believes the j-th fish is female if and only if the value in row i and column j if 1.
The last test case is followed by a zero, which means the end of the input.
[align=left]Output[/align]
Output the value for each test in a single line.
[align=left]Sample Input[/align]
3
1 2 3
011
101
110
0
[align=left]Sample Output[/align]
6
[align=left]Author[/align]
momodi@whu
[align=left]Source[/align]
The 5th Guangting Cup Central China Invitational Programming
Contest
[align=left]Recommend[/align]
notonlysuccess
题意:有一种鱼,它们可以攻击攻击别的鱼。但是只能攻击一次。每条鱼都有一个value。给你一个0,1矩阵。1代表第i条鱼攻击第j条鱼。并且能够spawned的概率是val[i]和val[j]的异或(XOR)。求所有的鱼最大的spawned值。二分匹配。
Special Fish
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1111 Accepted Submission(s): 422
[align=left]Problem Description[/align]
There is a kind of special fish in the East Lake where is closed to campus of Wuhan University. It’s hard to say which gender of those fish are, because every fish believes itself as a male, and it may attack one of some other fish
who is believed to be female by it.
A fish will spawn after it has been attacked. Each fish can attack one other fish and can only be attacked once. No matter a fish is attacked or not, it can still try to attack another fish which is believed to be female by it.
There is a value we assigned to each fish and the spawns that two fish spawned also have a value which can be calculated by XOR operator through the value of its parents.
We want to know the maximum possibility of the sum of the spawns.
[align=left]Input[/align]
The input consists of multiply test cases. The first line of each test case contains an integer n (0 < n <= 100), which is the number of the fish. The next line consists of n integers, indicating the value (0 < value <= 100) of each
fish. The next n lines, each line contains n integers, represent a 01 matrix. The i-th fish believes the j-th fish is female if and only if the value in row i and column j if 1.
The last test case is followed by a zero, which means the end of the input.
[align=left]Output[/align]
Output the value for each test in a single line.
[align=left]Sample Input[/align]
3
1 2 3
011
101
110
0
[align=left]Sample Output[/align]
6
[align=left]Author[/align]
momodi@whu
[align=left]Source[/align]
The 5th Guangting Cup Central China Invitational Programming
Contest
[align=left]Recommend[/align]
notonlysuccess
题意:有一种鱼,它们可以攻击攻击别的鱼。但是只能攻击一次。每条鱼都有一个value。给你一个0,1矩阵。1代表第i条鱼攻击第j条鱼。并且能够spawned的概率是val[i]和val[j]的异或(XOR)。求所有的鱼最大的spawned值。二分匹配。
#include<stdio.h> #include<string.h> #define inf 99999 using namespace std; int g[217][217]; int lx[217],ly[217]; int slack[217],match[217],val[217]; bool visx[217],visy[217]; int n; bool dfs(int cur) { visx[cur]=true; for(int y=1;y<=n;y++) { if(visy[y])continue; int t=lx[cur]+ly[y]-g[cur][y]; if(t==0) { visy[y]=true; if(match[y]==-1||dfs(match[y])) { match[y]=cur; return true; } } else if(slack[y]>t) { slack[y]=t; } } return false; } int KM() { memset(match,-1,sizeof(match)); memset(ly,0,sizeof(ly)); for(int i=1;i<=n;i++) { lx[i]=-inf; for(int j=1;j<=n;j++) { if(g[i][j]>lx[i]) lx[i]=g[i][j]; } } for(int x=1;x<=n;x++) { for(int i=1;i<=n;i++) slack[i]=inf; while(true) { memset(visx,false,sizeof(visx)); memset(visy,false,sizeof(visy)); if(dfs(x))break; int d=inf; for(int i=1;i<=n;i++) { if(!visy[i]&&d>slack[i]) d=slack[i]; } for(int i=1;i<=n;i++) if(visx[i]) { lx[i]-=d; } for(int i=1;i<=n;i++) if(visy[i])ly[i]+=d; else slack[i]-=d; } } int reslut=0,flag=0; for(int i=1;i<=n;i++) { if(match[i]==-1||g[match[i]][i]==-inf) continue; if(match[i]>-1) { reslut+=g[match[i]][i]; flag++; } } if(flag<n)reslut=-1; return reslut; } int main() { while(scanf("%d",&n),n) { for(int i=1;i<=n;i++) scanf("%d",&val[i]); char a; memset(g,0,sizeof(g)); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { scanf(" %c",&a); if(a=='1') g[i][j]=val[i]^val[j]; } int ans=KM(); printf("%d\n",ans); } return 0; }
相关文章推荐
- (hdu step 6.3.5)Card Game Cheater(匹配的最大数:a与b打牌,问b赢a多少次)
- hdu 2063 过山车(二分图最大匹配)
- HDU 1281 棋盘游戏(二分图最大匹配:关键边)
- HDU 1083 Courses (二分最大匹配)
- HDU 3279 二分图最大匹配
- HDU 2444 The Accomodation of Students(二分图判定+最大匹配)
- HDU-2063-最大匹配
- HDU 2819 Swap(最大匹配问题)
- HDU 4160 最小路径覆盖 = 顶点数 - 最大匹配数 二分匹配
- hdu 2063(二分图最大匹配,匈牙利算法,水题)
- HDU I'm Telling the Truth (二分图最大匹配+字典序最大路径输出(好题))
- HDU 1528 Card Game Cheater(二分图最大匹配)
- hdu 2444 判断是否构成二分图,并求最大匹配
- hdu 1281 棋盘游戏 最大匹配(经典题)
- hdu 1507 Uncle Tom's Inherited Land*(二分图最大匹配,黑白染色)
- HDU 2444 黑白染色判二分图+二分最大匹配
- HDU 1151Air Raid 最小路径覆盖=n-最大匹配量 (第二道二分匹配)
- hdu 3360 National Treasures 最小顶点覆盖(最大匹配)
- HDU 3395 Special Fish【最大权匹配】
- HDU 2063 过山车【二分图最大匹配】