1 Star 0 Fork 0

util6/算法刷题c++

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
AcWing376MachineTask.cpp 904 Bytes
一键复制 编辑 原始数据 按行查看 历史
util6 提交于 2022-03-28 22:20 +08:00 . 默认的
//
// Created by 刘宇韬 on 2022/3/19.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const int N = 110;
bool g[N][N];
bool st[N];
int n,m,k;
int match[N];
bool dfs(int u ){
for(int i = 0; i <m; i++) {
if (!st[i]&&g[u][i]){
st[i] = true;
if(match[i]==-1|| dfs(match[i])){
match[i] = u;
return true;
}
}
}
return false;
}
int main(){
while (cin>>n>>m>>k,n){
memset(g, 0,sizeof g);
memset(match, -1, sizeof match);
//读入每个任务
for(int i = 0; i <k; i++) {
int c,a,b;
cin>>c>>a>>b;
//因为2台机器初始都在模式0,所以用到0的任务不用后续处理
if (a==0||b==0 )continue;
//表示a->b有一条边
g[a][b] = true;
}
int res= 0;
for(int i = 0 ; i <n; i++) {
memset(st,0,sizeof st);
if (dfs(i))res++;
}
cout<<res;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuyutaocode/cppCode.git
git@gitee.com:liuyutaocode/cppCode.git
liuyutaocode
cppCode
算法刷题c++
master

搜索帮助