题目地址:UVA1194 Machine Schedule

二分图最小覆盖模型的要素

每条边有两个端点,二者至少选择一个。简称 \(2\) 要素。

\(2\) 要素在本题中的体现

每个任务要么在 \(A\) 上以 \(a_i\) 模式执行,要么在机器 \(B\) 上以 \(b_i\) 模式执行。

把 \(A,B\) 的 \(m\) 种模式分别作为 \(m\) 个左部点和右部点,每个任务作为边连接左部 \(a_i\) 节点和右部 \(b_i\) 节点。

求这张二分图的最小覆盖,时间复杂度为 \(O(nm)\) 。

#include <bits/stdc++.h>
using namespace std;
const int N = 106;
int n, m, k, f[N], ans;
bool v[N];
vector<int> e[N];

bool dfs(int x) {
    for (unsigned int i = 0; i < e[x].size(); i++) {
        int y = e[x][i];
        if (v[y]) continue;
        v[y] = 1;
        if (!f[y] || dfs(f[y])) {
            f[y] = x;
            return 1;
        }
    }
    return 0;
}

inline void Machine_Schedule() {
    cin >> m >> k;
    for (int i = 1; i <= n; i++) e[i].clear();
    for (int i = 0; i < k; i++) {
        int x, y;
        scanf("%d %d %d", &i, &x, &y);
        e[x].push_back(y);
    }
    memset(f, 0, sizeof(f));
    ans = 0;
    for (int i = 1; i <= n; i++) {
        memset(v, 0, sizeof(v));
        ans += dfs(i);
    }
    cout << ans << endl;
}

int main() {
    while (cin >> n && n) Machine_Schedule();
    return 0;
}

UVA1194 Machine Schedule的更多相关文章

  1. UVA1194 Machine Schedule[二分图最小点覆盖]

    题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...

  2. POJ 1325 Machine Schedule——S.B.S.

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13731   Accepted: 5873 ...

  3. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  4. Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. hdu-----(1150)Machine Schedule(最小覆盖点)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. poj 1325 Machine Schedule 二分匹配,可以用最大流来做

    题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...

  7. hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. POJ1325 Machine Schedule 【二分图最小顶点覆盖】

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11958   Accepted: 5094 ...

  9. HDU 1150:Machine Schedule(二分匹配,匈牙利算法)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

随机推荐

  1. python中字符编码及unicode和utf-8区别

    ascii和unicode是字符集,utf-8是编码集 字符集:为每一个「字符」分配一个唯一的 ID(学名为码位 / 码点 / Code Point) 编码规则:将「码位」转换为字节序列的规则(编码/ ...

  2. window.location.reload();页面实现跳转和刷新

    1 history.go(0)2 location.reload()3 location=location4 location.assign(location)5 document.execComma ...

  3. js 日期 相关

    Js计算指定日期加上多少天.加多少月.加多少年的日期 function DateAdd(interval, number, date) { switch (interval) { case " ...

  4. man termios(FreeBSD 12.0)

    TERMIOS() FreeBSD Kernel Interfaces Manual TERMIOS() NAME termios - general terminal line discipline ...

  5. 关于TCP/IOCP构架中出现的Socket假死连接解决方案

    如果在2台不同的公网机器,对TCP的c/s做过详细的压力测试,那么很不幸,会有很多人发现自己的server端会出现大量的假死连接. 假死连接具体表现如下: 1.在s端机器上,会有一些处于TCP_EST ...

  6. 20155324 《Java程序设计》实验五 网络编程与安全

    20155324 <Java程序设计>实验五 网络编程与安全 实验内容 任务一 编写MyBC.java实现中缀表达式转后缀表达式的功能 编写MyDC.java实现从上面功能中获取的表达式中 ...

  7. cuda、cuDNN的相关内容

    1.nvidia与cuda需要满足关系: https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html/ 2.cuda与cudn ...

  8. github上face_recognition工程项目实践

    一.安装开发环境 1.安装dlib和相关Python依赖 先下载dlib源码: git clone https://github.com/davisking/dlib.git 编译dlib源码:(可以 ...

  9. kettle mysql 乱码

    在数据库连接上添加字符集编码参数characterEncoding, 指定UTF8或GBK

  10. 第19月第17天 uitextview 文本垂直居中 uiimage中间不拉伸

    1. open class VericalCenteringScrollView: UIScrollView { override open var contentOffset: CGPoint { ...