http://poj.org/problem?id=3436

每台电脑有$p$个组成部分,有$n$个工厂加工电脑。

每个工厂对于进入工厂的半成品的每个组成部分都有要求,由$p$个数字描述,0代表这个部分不能有,1代表这个部分必须有,2代表这个部分的有无无所谓。

每个工厂的产出也不尽相同,也是由p个数字代表,0代表这个部分不存在,1代表这个部分存在。每个工厂都有一个最大加工量。

给出这$n$个工厂的数据,求出最多能加工出多少台电脑

对于容量有限制,因此拆点

开始的机器没有零件,连接符合要求的点

最终的机器应该是完整的,把符合要求的点连接到汇点

因为已经拆过点限制了流量,所以其余容量记为INF就行了,

关于路径还原 在链式前向星保存边的时候同时记录边的起点,最后反向弧非零的边就是答案

#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <iostream>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pp pair<int,int>
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#define per(ii,a,b) for(int ii=a;ii>=b;ii--)
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(a,b) cout<<#a<<'['<<b<<"]="<<b[a]<<endl
using namespace std;
const int maxn=123+10;
const int maxm=1234+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
struct node {int pre,to,cap,next;}e[maxm];
int ss,tt,head[maxn],nume,dis[maxn];
inline void addx(int a,int b,int c){
e[++nume]=(node){a,b,c,head[a]};
head[a]=nume;
}
inline void add(int a,int b,int c){
addx(a,b,c);addx(b,a,0);
}
bool bfs(int s=ss,int t=tt){
int top=0,end=1;
int q[maxn];
q[0]=s;
// for(int i=0;i<=t;i++) dis[i]=0;
memset(dis,0,sizeof dis);
dis[s]=1;
while(top!=end){
int now=q[top++];top%=maxn;
for(int i=head[now];i;i=e[i].next){
int to=e[i].to;
if(!dis[to]&&e[i].cap){
dis[to]=dis[now]+1;
if(to==t)break;
q[end++]=to;end%=maxn;
}
}
}
return dis[t];
}
int dfs(int now=ss,int last=INF){
if(now==tt)return last;
int flow=0,det;
for(int i=head[now];i;i=e[i].next){
int to=e[i].to;
if(e[i].cap&&dis[to]==dis[now]+1){
det=dfs(to,min(last-flow,e[i].cap));
flow+=det;
e[i].cap-=det;
e[i^1].cap+=det;
if(flow==last) return last;
}
}
dis[now]=-1;
return flow;
}
int p;
int cost[123];
int in[123][12];
int out[123][12];
int a[123];
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
nume=1;
IO;
cin>>p>>n;
ss=0,tt=2*n+1;
nume=1;
rep(i,1,n){
cin>>cost[i];
int cnt=0;
rep(j,1,p){
cin>>in[i][j];
if(in[i][j]!=1) cnt++;
}
if(cnt==p) add(ss,i,INF);
cnt=0;
rep(j,1,p){
cin>>out[i][j];
if(out[i][j]==1) cnt++;
}
if(cnt==p) add(i+n,tt,INF);
add(i,i+n,cost[i]);
}
rep(i,1,n){
rep(j,1,n){
if(i==j) continue;
int cnt=0;
rep(k,1,p){
if(in[j][k]!=2&&in[j][k]!=out[i][k]){
cnt++;
break;
}
}
if(cnt==0) add(i+n,j,INF);
}
}
int ans=0;
while(bfs()) ans+=dfs();
if(ans==0) cout<<"0 0\n";
else {
int cnt=0;
for(int i=2;i<=nume;i+=2){
if(abs(e[i].pre-e[i].to)!=n&&e[i].to>ss&&e[i].pre>ss&&e[i].pre<tt&&e[i].to<tt&&e[i^1].cap!=0){
a[cnt++]=i;
}
}
cout<<ans<<' '<<cnt<<'\n';
rep(i,0,cnt-1){
cout<<e[a[i]].pre-n<<' '<<e[a[i]].to<<' '<<e[a[i]^1].cap<<'\n';
}
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

  

ACM Computer Factory POJ - 3436 网络流拆点+路径还原的更多相关文章

  1. A - ACM Computer Factory POJ - 3436 网络流

    A - ACM Computer Factory POJ - 3436 As you know, all the computers used for ACM contests must be ide ...

  2. ACM Computer Factory - poj 3436 (最大流)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5949   Accepted: 2053   Special Judge ...

  3. (网络流)ACM Computer Factory --POJ --3436

    链接: http://poj.org/problem?id=3436 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82835#probl ...

  4. A - ACM Computer Factory - poj 3436(最大流)

    题意:有一个ACM工厂会生产一些电脑,在这个工厂里面有一些生产线,分别生产不同的零件,不过他们生产的电脑可能是一体机,所以只能一些零件加工后别的生产线才可以继续加工,比如产品A在生产线1号加工后继续前 ...

  5. poj3436 ACM Computer Factory, 最大流,输出路径

    POJ 3436 ACM Computer Factory 电脑公司生产电脑有N个机器.每一个机器单位时间产量为Qi. 电脑由P个部件组成,每一个机器工作时仅仅能把有某些部件的半成品电脑(或什么都没有 ...

  6. POJ-3436 ACM Computer Factory 最大流 为何拆点

    题目链接:https://cn.vjudge.net/problem/POJ-3436 题意 懒得翻,找了个题意. 流水线上有N台机器装电脑,电脑有P个部件,每台机器有三个参数,产量,输入规格,输出规 ...

  7. POJ 3436 ACM Computer Factory (网络流,最大流)

    POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...

  8. POJ 3436:ACM Computer Factory 网络流

    ACM Computer Factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6247   Accepted: 2 ...

  9. Poj 3436 ACM Computer Factory (最大流)

    题目链接: Poj 3436 ACM Computer Factory 题目描述: n个工厂,每个工厂能把电脑s态转化为d态,每个电脑有p个部件,问整个工厂系统在每个小时内最多能加工多少台电脑? 解题 ...

随机推荐

  1. Swagger入门

    新手入门Swagger看了很多博客,竟然没有一个是步骤齐全的或直接能运行的.于是CSDN下载了SSM+Swagger整合的demo,一顿瞎整,终于可以运行了. 不容易,因此分享这篇博客,祝新手朋友们早 ...

  2. Scrapy基础01

    一.Scarpy简介 Scrapy基于事件驱动网络框架 Twisted 编写.(Event-driven networking) 因此,Scrapy基于并发性考虑由非阻塞(即异步)的实现. 参考:武S ...

  3. protobuf使用简介

    官网:https://github.com/google/protobuf 环境:windows,java 1. protobuf概述protobuf是Google开发一种数据描述格式,能够将结构化数 ...

  4. 指定so动态链接库连接器

    在学习x86_64汇编时, 发现一旦使用glibc库函数, 如printf时, 一般是需要使用为ld传递命令行参数-lc来动态连接libc.so的, 但是, 生成的可执行文件却无法运行: 气煞我也! ...

  5. vue.js 树菜单 递归组件树来实现

    树形视图 Example: https://vuefe.cn/v2/examples/tree-view.html 参照前辈方法实现的,觉得不错,记录一下: 父组件: <!-- 菜单树 --&g ...

  6. Nginx负载均衡session会话保持方法

    负载均衡时,为了保证同一用户session会被分配到同一台服务器上,可以使用以下方法: 1.使用cookie 将用户的session存入cookie里,当用户分配到不同的服务器时,先判断服务器是否存在 ...

  7. solr window环境安装配置和管理页面基本使用

    solr介绍 来自官网http://lucene.apache.org/solr/解释: Solr is highly reliable, scalable and fault tolerant, p ...

  8. nginx: [error] CreateFile() "E:\nginx\nginx-1.9.3/logs/nginx.pid" failed

    nginx: [error] CreateFile() "E:\nginx\nginx-1.9.3/logs/nginx.pid" failed nginx: [error] Op ...

  9. Debian Security Advisory(Debian安全报告) DSA-4405-1 openjpeg2

    package :openjpeg2 相关CVE ID: CVE-2017-17480 CVE-2018-5785 CVE-2018-6616 CVE-2018-14423 CVE-2018-1808 ...

  10. Django的csrf中间件

    csrf中间件 ​ csrf 跨站请求伪造 ​ 补充两个装饰器: ​ from django.views.decorators.csrf import csrf_exempt,csrf_protect ...