日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > [ACM] HDU 3395 Special Fish (二分圖最大權匹配,KM算法)

[ACM] HDU 3395 Special Fish (二分圖最大權匹配,KM算法)

來源:程序員人生   發布時間:2014-11-05 08:03:52 閱讀次數:2294次

Special Fish



Problem Description
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.
 

Input
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.
 

Output
Output the value for each test in a single line.
 

Sample Input
3 1 2 3 011 101 110 0
 

Sample Output
6
 

Author
momodi@whu
 

Source
The 5th Guangting Cup Central China Invitational Programming Contest
 

Recommend
notonlysuccess   |   We have carefully selected several similar problems for you:  1533 1853 2448 3388 3392 


解題思路:

題意為有n條特殊的魚,每一個魚都有1個價值,如果魚i ”認為“ 魚j 性別不同,那末就攻擊它,繁殖的后代的價值為 v[i] ^ v[j], 每條魚只能攻擊或被攻擊1次,問最后繁殖的后代的最大價值為多少。

也是比較裸的2分圖最大權不匹配,邊i,j的權值等于 v[i] ^ v[j] 。

http://blog.csdn.net/sr_19930829/article/details/40650359

代碼:

#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> using namespace std; const int maxn=102; const int inf=0x3f3f3f; int nx,ny;//左右兩邊的點數 int v[maxn];//每條魚的value int g[maxn][maxn];//鄰接矩陣 int linked[maxn];//右側的點和左側哪一個點連接 int lx[maxn],ly[maxn];//左右點的標號 int slack[maxn];//slack[j]表示右側的點j的所有不在導出子圖的邊對應的lx[i]+ly[j]-w[i][j]的最小值 bool visx[maxn],visy[maxn]; bool DFS(int x)//hungary求增廣路 { visx[x]=true; for(int y=0;y<ny;y++) { if(visy[y]) continue; int tmp=lx[x]+ly[y]-g[x][y]; if(tmp==0) { visy[y]=true; if(linked[y]==⑴||DFS(linked[y])) { linked[y]=x; return true; } } else if(slack[y]>tmp) slack[y]=tmp; } return false; } int KM() { memset(linked,⑴,sizeof(linked)); memset(ly,0,sizeof(ly)); for(int i=0;i<nx;i++) { lx[i]=-inf; for(int j=0;j<ny;j++) if(g[i][j]>lx[i]) lx[i]=g[i][j]; } for(int x=0;x<nx;x++) { for(int y=0;y<ny;y++) slack[y]=inf; while(true) { memset(visx,0,sizeof(visx)); memset(visy,0,sizeof(visy)); if(DFS(x)) break; int d=inf; for(int y=0;y<ny;y++) if(!visy[y]&&d>slack[y]) d=slack[y]; for(int i=0;i<nx;i++) if(visx[i]) lx[i]-=d; for(int i=0;i<ny;i++) { if(visy[i]) ly[i]+=d; else slack[i]-=d; } } } int ans=0; for(int y=0;y<ny;y++) { if(linked[y]!=⑴) ans+=g[linked[y]][y]; } return ans; } int main() { int n; while(scanf("%d",&n)!=EOF&&n) { nx=ny=n; for(int i=0;i<n;i++) scanf("%d",&v[i]); int ch; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { scanf("%1d",&ch);//輸入格式1d if(ch==1) g[i][j]=v[i]^v[j]; else g[i][j]=0; } } printf("%d ",KM()); } return 0; }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 天天干夜夜操 | 国产精品18久久久久久久网站 | 国产精品免费一区二区 | 欧美午夜一区二区 | 欧美亚洲国产精品 | 精品国产第一国产综合精品 | 黄色高清网站 | 国产精品一区免费视频 | 高清一二三区 | 黄a免费视频 | 日韩成人免费在线 | 黄a网站 | 精品人人 | 伊人三区 | a级片毛片 | 久久久91精品国产 | 国产成人小视频 | 夜夜爱av | 在线观看国产一区 | a级毛片免费网站 | 精品国产乱码久久久 | 在线三区| 免费看成人吃奶视频在线 | 成人看片 | 国语对白av | 黄色一级片 | 国内毛片毛片 | 美女视频一区 | 污污的网站在线免费观看 | 日韩一区三区 | 久久久久中文字幕 | 午夜精品视频 | 久一久久| 国产一区二区三区视频在线观看 | 91久久久久久久久久久 | 国产午夜精品久久久久久久 | 日韩久久一区二区 | 免费久久网 | 美女又爽又黄视频毛茸茸 | 久久99成人 | 日韩精品一区二区三区在线 |