HDU 3395 Special Fish 二分匹配(求最大匹配值)

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并着重介绍了AI音视频处理在游戏中的应用,如语音识别、图像处理、AR特效等。同时,文章还涉及了自动化测试、性能优化等现代开发流程,旨在为游戏开发者提供全面的技术指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

 

 

Special Fish

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1111    Accepted Submission(s): 422


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
 


 

Recommend
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;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值