zoukankan      html  css  js  c++  java
  • hdu2063+hdu1083(最大匹配数)

    传送门:hdu2063过山车 

    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <cstdlib>
    #include <stack>
    #include <vector>
    #include <set>
    #include <map>
    #define LL long long
    #define mod 100000000
    #define inf 0x3f3f3f3f
    #define eps 1e-6
    #define N 510
    #define FILL(a,b) (memset(a,b,sizeof(a)))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define PII pair<int,int>
    using namespace std;
    int g[N][N],vis[N],linker[N];
    int n,m;
    int dfs(int u)
    {
        for(int i=1;i<=m;i++)
        if(g[u][i]&&!vis[i])
        {
            vis[i]=1;
            if(linker[i]==-1||dfs(linker[i]))
            {
                linker[i]=u;
                return 1;
            }
        }
        return 0;
    }
    int main()
    {
        int k;
        while(scanf("%d",&k),k)
        {
            scanf("%d%d",&n,&m);
            FILL(g,0);FILL(linker,-1);
            while(k--)
            {
                int u,v;
                scanf("%d%d",&u,&v);
                g[u][v]=1;
            }
            int ans=0;
            for(int i=1;i<=n;i++)
            {
                FILL(vis,0);
                if(dfs(i))ans++;
            }
            printf("%d
    ",ans);
        }
    }
    View Code

    传送门:hdu1083 courses 

    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <cstdlib>
    #include <stack>
    #include <vector>
    #include <set>
    #include <map>
    #define LL long long
    #define mod 100000000
    #define inf 0x3f3f3f3f
    #define eps 1e-6
    #define N 310
    #define FILL(a,b) (memset(a,b,sizeof(a)))
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define PII pair<int,int>
    using namespace std;
    int g[N][N],vis[N],match[N];
    int n,m;
    int dfs(int u)
    {
        for(int i=1;i<=m;i++)
        if(g[u][i]&&!vis[i])
        {
            vis[i]=1;
            if(match[i]==-1||dfs(match[i]))
            {
                match[i]=u;
                return 1;
            }
        }
        return 0;
    }
    int main()
    {
        int t,num,x;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            FILL(g,0);FILL(match,-1);
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&num);
                while(num--)
                {
                    scanf("%d",&x);
                    g[i][x]=1;
                }
            }
            int sum=0;
            for(int i=1;i<=n;i++)
            {
                FILL(vis,0);
                if(dfs(i))sum++;
            }
            if(sum==n)puts("YES");
            else puts("NO");
        }
    }
    View Code
  • 相关阅读:
    算法
    算法
    算法
    算法
    mysql使用注意事项
    公共接口限制IP请求次数的一种方式(redis版)
    vue echarts 折线图 饼图 地图
    springboot Redis缓存应用示例
    springboot 响应消息 message简单封装 单例和原型模式
    springboot 请求外部接口方法
  • 原文地址:https://www.cnblogs.com/lienus/p/4285052.html
Copyright © 2011-2022 走看看