bzoj4443:[Scoi2015]小凸玩矩阵

传送门

二分答案是显然的啊,然后对于比二分出的值大的直接跑最大匹配,然后判定就好了
代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
void read(int &x) {
    char ch; bool ok;
    for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
    for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=260;
int n,m,k,f[maxn],ans,a[maxn][maxn];bool vis[maxn],used[maxn][maxn];
bool dfs(int x)
{
    for(rg int i=1;i<=m;i++)
        if(!used[x][i]&&!vis[i])
        {
            vis[i]=1;
            if(!f[i]||dfs(f[i])){f[i]=x;return 1;}
        }
    return 0;
}
bool check(int v)
{
    memset(f,0,sizeof f),memset(used,0,sizeof used),ans=0;
    for(rg int i=1;i<=n;i++)
        for(rg int j=1;j<=m;j++)
            if(a[i][j]>=v)used[i][j]=1;
    for(rg int i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);
        if(dfs(i))ans++;
    }
    return ans>=n-k+1;
}
int main()
{
    read(n),read(m),read(k);
    for(rg int i=1;i<=n;i++)for(rg int j=1;j<=m;j++)read(a[i][j]);
    int l=0,r=1e9;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(check(mid))r=mid-1;
        else l=mid+1;
    }
    printf("%d\n",r);
}
posted @ 2019-03-25 16:36 蒟蒻--lichenxi 阅读(...) 评论(...) 编辑 收藏