多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > 互聯(lián)網(wǎng) > [ACM] HDU 3395 Special Fish (二分圖最大權(quán)匹配,KM算法)

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

來源:程序員人生   發(fā)布時間:2014-11-05 08:03:52 閱讀次數(shù):2288次

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個價(jià)值,如果魚i ”認(rèn)為“ 魚j 性別不同,那末就攻擊它,繁殖的后代的價(jià)值為 v[i] ^ v[j], 每條魚只能攻擊或被攻擊1次,問最后繁殖的后代的最大價(jià)值為多少。

也是比較裸的2分圖最大權(quán)不匹配,邊i,j的權(quán)值等于 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;//左右兩邊的點(diǎn)數(shù) int v[maxn];//每條魚的value int g[maxn][maxn];//鄰接矩陣 int linked[maxn];//右側(cè)的點(diǎn)和左側(cè)哪一個點(diǎn)連接 int lx[maxn],ly[maxn];//左右點(diǎn)的標(biāo)號 int slack[maxn];//slack[j]表示右側(cè)的點(diǎn)j的所有不在導(dǎo)出子圖的邊對應(yīng)的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; }



生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 国产精品二区三区免费播放心 | 国产高清在线视频一区二区三区 | 五月视频| 亚洲综合性 | 黄色网址免费观看 | 欧美日韩亚洲综合在线一区二区 | 久草在线视频福利 | 国产精品欧美亚洲 | 亚洲欧美国产另类 | 亚洲 春色 古典 小说 自拍 | 国产三区视频 | 欧美色交 | 午夜dj在线观看免费高清在线 | www.欧美色| 亚洲精品一区二区中文 | 亚洲精品免费在线观看 | 波多野结衣成人 | 国产精品一区二区三区四区 | 欧美另类丰满69xxxxx | 日产高清卡一卡二无卡三区 | 成人国产在线视频在线观看 | 日本免费中文字幕在线看 | jizz18高清视频| 亚洲天堂久久新 | 亚洲免费人成在线视频观看 | 国产亚洲精品不卡在线 | 精品日韩欧美一区二区三区 | 最近2019中文字幕免费看最新 | 国产精品国产亚洲精品看不卡 | yellow中文字幕在线高清 | 激情另类国内一区二区视频 | 免费在线日本 | 中文字幕欧美亚洲 | 久久三级影视 | 国产高清福利91成人 | 欧美日韩亚洲一区二区三区 | 国产精品11页 | 亚洲高清在线视频 | 午夜老司机永久免费看片 | 羞色影院| 免费一区二区三区久久 |