zoukankan      html  css  js  c++  java
  • AcWing 376. 机器任务

    算法

    二分图+最小点覆盖

    思路

    节点

    A的模式为左部节点,B的模式为右部节点

    一个物品的A与B间连边。

    2要素

    及一条边中必选有一个节点 ,(要么在A加工,要么在B加工)

    代码

    #include <cstdio>
    #include <vector>
    #include <cstring>
    #include <iostream>
    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);
    		if (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;
    }
    

      

  • 相关阅读:
    华师菜鸟杯2020
    「算法」排序
    生成函数
    多项式乘法逆
    多项式牛顿迭代
    「数学」快速幂
    「算法」贪心
    「组合数学」一:什么是组合数学
    「具体数学」三:整值函数
    「图论」树上问题
  • 原文地址:https://www.cnblogs.com/ruanmowen/p/12724744.html
Copyright © 2011-2022 走看看