zoukankan      html  css  js  c++  java
  • BZOJ1143: [CTSC2008]祭祀river

    【传送门:BZOJ1143


    简要题意:

      给出一个有向无环图,选出最多的点,使得这些点不能互相到达


    题解:

      最长反链=最小链覆盖=最大独立集,然后二分图匹配

      如果x能到达y,则将x连向y的另一个集合


    参考代码:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<cstdlib>
    using namespace std;
    int match[110],chw[110];
    bool map[110][110];
    int n;
    bool findmuniu(int x,int t)
    {
        for(int y=1;y<=n;y++)
        {
            if(chw[y]!=t&&map[x][y]==true)
            {
                chw[y]=t;
                if(match[y]==0||findmuniu(match[y],t)==true)
                {
                    match[y]=x;
                    return true;
                }
            }
        }
        return false;
    }
    int main()
    {
        int m;
        scanf("%d%d",&n,&m);
        memset(map,false,sizeof(map));
        for(int i=1;i<=m;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            map[x][y]=true;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i!=j)
                {
                    for(int k=1;k<=n;k++)
                    {
                        if(i!=k&&k!=j)
                        {
                            if(map[i][j]==true&&map[j][k]==true) map[i][k]=true;
                        }
                    }
                }
            }
        }
        memset(chw,0,sizeof(chw));
        memset(match,0,sizeof(match));
        int sum=n;
        for(int i=1;i<=n;i++) if(findmuniu(i,i)==true) sum--;
        printf("%d
    ",sum);
        return 0;
    }

     

  • 相关阅读:
    程序集冲突问题
    Linux 菜鸟学习笔记--系统分区
    gawk
    Ansible
    Linux 网关及路由
    Linux档案与目录管理
    find命令
    sed详解
    FTP服务
    Gentoo安装(虚拟机)
  • 原文地址:https://www.cnblogs.com/Never-mind/p/8634495.html
Copyright © 2011-2022 走看看