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. MySQL数据类型1

    1.float.double.decimal类型用法详解 三者的区别介绍 float:浮点型,含字节数为4,32bit,数值范围为-3.4E38~3.4E38(7个有效位) double:双精度实型, ...

  2. 阅读:重新介绍 JavaScript(JS教程)

    这篇文章是记录自己阅读重新介绍 JavaScript(JS 教程)的记录和个人体会 在线调试代码工具:https://codepen.io/pen 引言 分歧根源:名字Javascript和Java有 ...

  3. ArcGis Python脚本——批量对影像、要素类定义投影

    这一段是批量定义要素类(FeatureClasses)投影的ArcPy代码: 把要处理的要素类塞进一个文件夹(工作空间,workspace),然后将代码开头的路径换成这个“文件夹”的路径,处理完后再做 ...

  4. 我的长大app开发教程第三弹:实现四个子页面绑定RadioButton

    在开始之前先上一张图 在上一节中我们实现了底部Button,这一弹我们要实现点击四个按钮分别切换到不同页面,我们可以把页面分为两部分,顶部栏和中间内容部分,我们可以通过线性布局包裹两部分内容,顶部栏又 ...

  5. 进入页面就触发了popstate事件。

     $(function () {             pushHistory();             setTimeout(function () {                 win ...

  6. JQuery Rest客户端库

    JQuery Rest https://github.com/jpillora/jquery.rest/ Summary A jQuery plugin for easy consumption of ...

  7. Polymer初探

    Polymer是什么? Polymer英文为 n.聚合物:多聚体 网络高分子:聚合体:高分子聚合物 应用在Web组件场景, 表达的是, 一个一个小的Web组件,可以通过此框架聚合为一个 整个页面. h ...

  8. redis的持久化方案

    Redis的高性能是由于其将所有数据都存储在了内存中,为了使Redis在重启之后仍能保证数据不丢失,需要将数据从内存中同步到硬盘中,这一过程就是持久化. Redis支持两种方式的持久化,一种是RDB方 ...

  9. 服务器上定时自动执行php

    两种方式: 一.Linux 服务器Linux原生支持crontab,所以可以利用这一功能做定时任务 步骤: 1.编辑crontab文件:Linux:crontab -e 2.输入代码:0 0 * * ...

  10. labelImg 工具

    安装anaconda, 在anaconda prompt 下 执行 pyrcc4 -o resources.py resources.qrc python labelImg.py