zoukankan      html  css  js  c++  java
  • HDU1150 Machine Schedule 最小点覆盖

      题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150

      建立图后,很容易发现是最小点覆盖。

     1 //STATUS:G++_AC_0MS_400KB
     2 #include<stdio.h>
     3 #include<stdlib.h>
     4 #include<string.h>
     5 #include<math.h>
     6 #include<iostream>
     7 #include<string>
     8 #include<algorithm>
     9 #include<vector>
    10 #include<queue>
    11 #include<stack>
    12 #include<map>
    13 using namespace std;
    14 #define LL long long
    15 #define Max(a,b) ((a)>(b)?(a):(b))
    16 #define Min(a,b) ((a)<(b)?(a):(b))
    17 #define mem(a,b) memset(a,b,sizeof(a))
    18 #define lson l,mid,rt<<1
    19 #define rson mid+1,r,rt<<1|1
    20 const int MAX=110,INF=0x3f3f3f3f;
    21 
    22 int g[MAX][MAX],y[MAX],vis[MAX];
    23 int n,m,k;
    24 
    25 int dfs(int u)
    26 {
    27     int v;
    28     for(v=1;v<=m;v++){
    29         if(g[u][v] && !vis[v]){
    30             vis[v]=1;
    31             if(!y[v] || dfs(y[v])){
    32                 y[v]=u;
    33                 return 1;
    34             }
    35         }
    36     }
    37     return 0;
    38 }
    39 
    40 int main()
    41 {
    42  //   freopen("in.txt","r",stdin);
    43     int i,j,k,ans,a,b,t;
    44     while(~scanf("%d",&n) && n)
    45     {
    46         ans=0;
    47         mem(y,0);
    48         mem(g,0);
    49         scanf("%d%d",&m,&k);
    50         for(i=0;i<k;i++){
    51             scanf("%d%d%d",&t,&a,&b);
    52             g[a][b]=1;
    53         }
    54 
    55         for(i=1;i<=n;i++){
    56             mem(vis,0);
    57             if(dfs(i))ans++;
    58         }
    59 
    60         printf("%d\n",ans);
    61     }
    62     return 0;
    63 }
  • 相关阅读:
    0919 作业
    0918 登录注册
    20190918 文件处理
    20190917 字符编码
    0916 作业
    0916 数据类型与深浅拷贝
    0913 作业
    0912 for循环及内置方法
    0911 作业
    Ubuntu同时忘记用户密码和root密码
  • 原文地址:https://www.cnblogs.com/zhsl/p/2787840.html
Copyright © 2011-2022 走看看