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. Linux记录-salt分析

    salt-master建立分组 如dn: 'L@dnxxx,dyyy' salt -N dn  state.apply  hadoop test=true salt -N dn  cmd.run  ' ...

  2. centos 6.5 安装jdk1.8

    1.源码包准备: 首先到官网下载jdk-8u66-linux-x64.tar.gz, http://www.oracle.com/technetwork/java/javase/downloads/j ...

  3. 使用Calender类获取系统时间和时间和运算

    使用Calender类获取系统时间和时间和运算: @Test public void testCal(){ //使用Calender对象获取时间,并对时间进行计算: Calendar instance ...

  4. Django路由层

    路由层简单配置 urlpatterns = [ url(r'^admin/$', admin.site.urls), url(r'^articles/2003/$', views.special_ca ...

  5. Silverlight中字典的使用

    通过值搜索字典中的项: FristOfDefault返回序列中满足条件的第一个元素:如果未找到这样的元素,则返回默认值.

  6. VS2019预览版发布了

     VS2019正式版已发布:https://www.cnblogs.com/zhaogaojian/p/10648904.html 1.点击下载https://visualstudio.microso ...

  7. springboot 02-PropertiesFile 自定义配置属性,多环境配置

    application.properties: # 自定义配置 test.hello.world = HelloWorld test.person.name = 哈哈 test.person.sex ...

  8. PySpider 爬虫系统

    PySpider:一个国人编写的强大的网络爬虫系统并带有强大的WebUI.采用Python语言编写,分布式架构,支持多种数据库后端,强大的WebUI支持脚本编辑器,任务监视器,项目管理器以及结果查看器 ...

  9. remove() 方法

    jQuery的 remove() 方法,去掉选中元素. 例如: $("button").click(function(){ $("p").remove(); } ...

  10. Chrome实用技巧集锦

    1. 截取整个网页内容: 步骤:(F12 或 Ctrl Shift I 进入开发者模式)  ——>  Ctrl Shift P 弹出输入框  ——>  输入框中输入:Captrue ful ...