ACM Computer Factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6012   Accepted: 2083   Special Judge

Description

As you know, all the computers used for ACM contests must be identical, so the participants compete on equal terms. That is why all these computers are historically produced at the same factory.

Every ACM computer consists of P parts. When all these parts are present, the computer is ready and can be shipped to one of the numerous ACM contests.

Computer manufacturing is fully automated by using N various machines. Each machine removes some parts from a half-finished computer and adds some new parts (removing of parts is sometimes necessary as the parts cannot be added to a computer in arbitrary order). Each machine is described by its performance (measured in computers per hour), input and output specification.

Input specification describes which parts must be present in a half-finished computer for the machine to be able to operate on it. The specification is a set of P numbers 0, 1 or 2 (one number for each part), where 0 means that corresponding part must not be present, 1 — the part is required, 2 — presence of the part doesn't matter.

Output specification describes the result of the operation, and is a set of P numbers 0 or 1, where 0 means that the part is absent, 1 — the part is present.

The machines are connected by very fast production lines so that delivery time is negligibly small compared to production time.

After many years of operation the overall performance of the ACM Computer Factory became insufficient for satisfying the growing contest needs. That is why ACM directorate decided to upgrade the factory.

As different machines were installed in different time periods, they were often not optimally connected to the existing factory machines. It was noted that the easiest way to upgrade the factory is to rearrange production lines. ACM directorate decided to entrust you with solving this problem.

Input

Input file contains integers P N, then N descriptions of the machines. The description of ith machine is represented as by 2 P + 1 integers Qi Si,1 Si,2...Si,P Di,1 Di,2...Di,P, where Qi specifies performance, Si,j — input specification for part j, Di,k — output specification for part k.

Constraints

1 ≤ P ≤ 10, 1 ≤ N ≤ 50, 1 ≤ Qi ≤ 10000

Output

Output the maximum possible overall performance, then M — number of connections that must be made, then M descriptions of the connections. Each connection between machines A and B must be described by three positive numbers A B W, where W is the number of computers delivered from A to B per hour.

If several solutions exist, output any of them.

Sample Input

Sample input 1
3 4
15 0 0 0 0 1 0
10 0 0 0 0 1 1
30 0 1 2 1 1 1
3 0 2 1 1 1 1
Sample input 2
3 5
5 0 0 0 0 1 0
100 0 1 0 1 0 1
3 0 1 0 1 1 0
1 1 0 1 1 1 0
300 1 1 2 1 1 1
Sample input 3
2 2
100 0 0 1 0
200 0 1 1 1

Sample Output

Sample output 1
25 2
1 3 15
2 3 10
Sample output 2
4 5
1 3 3
3 5 3
1 2 1
2 4 1
4 5 1
Sample output 3
0 0

Hint

Bold texts appearing in the sample sections are informative and do not form part of the actual data.

Source

Northeastern Europe 2005, Far-Eastern Subregion
 
 
 

大概题意,每个机器有P个组件组成,现在给你M个机器的信息,问你最多能组装多少个电脑。

没行第一个参数 能容纳多少台电脑(可以看成网络流中,没条路的容量)

接下来有2P个参数 0 表示不需要 1表示必须有 2可以可有可无第2~p个参数 分别是安装这个电脑前需要的的条件

第p+1个参数到2P个参数表示 安装好后的机器具备那些组件例1测试数据:

3 4

15  0 0 0  0 1 0

10  0 0 0  0 1 1

30  0 1 2  1 1 1

3    0 2 1  1 1 1

第一台机器可以装容纳15台机器,生产条件是全0(红色部分) 生产结果是(绿色部分) 这里只有第3第4台机器可以把整台电脑安装好,而进入机器3需要条件 0 1 2也就是第二个部件必须有,显然刚由1生产过的电脑能送到机器3组装成完整的电脑

这里我们可以采用拆点的方法去建立一个图来进行最短增广路得出结果当然需要有一个超级汇点和超级源点,显然把生产条件都是0的与超级源点相连,生产结果全为1的与超级汇点相连 权值当然是无穷大。然后把每台机器的生产条件和生产结果连接起来,因为在同一台机器。当然是连通的拉!权值当然是自己所能容纳的量机器之间怎么连接?00 11 21 12都可以匹配,而01 10就不能匹配,所以我们就可以轻易得出结论同部件相加等于1的机器不能相连;相连的机器权值为无穷大,这样我们的图就建好了!然后就可以用spfa,EK,dinic等算法解决,我这里用的是ISAP。

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
int p,n;
int a[][];
int edge[][];
int flow[][];
int start,end;
int head[];
int pp[];
int EK(){
memset(flow,,sizeof(flow));
memset(head,-,sizeof(head)); int sum=;
while(true){
queue<int>q;
q.push(start);
memset(pp,,sizeof(pp)); pp[start]=0x7fffffff; while(!q.empty()){
int u=q.front();
q.pop();
for(int v=;v<=n+;v++){
if(!pp[v]&&edge[u][v]>flow[u][v]){
head[v]=u;
q.push(v);
pp[v]=min(pp[u],edge[u][v]-flow[u][v]); }
} } if(pp[end]==)
break;
for(int i=end;i!=start;i=head[i]){
flow[head[i]][i]+=pp[end];
flow[i][head[i]]-=pp[end];
}
sum+=pp[end];
}
return sum; }
int main(){
while(scanf("%d%d",&p,&n)!=EOF){
memset(a,,sizeof(a));
memset(edge,,sizeof(edge));
start=;
end=n+;
for(int i=;i<=*p+;i++){
a[][i]=;
a[n+][i]=;
}
for(int i=;i<=n;i++){
for(int j=;j<=*p;j++){
scanf("%d",&a[i][j]);
}
} for(int i=;i<=n+;i++){
for(int j=;j<=n+;j++){
if(i==j)
continue;
bool flag=true;
for(int k=;k<=p;k++){
if(!(a[j][k]==||a[i][k+p]==a[j][k]))
flag=false; } if(flag&&i==){
edge[][j]=a[j][];
}
else if(flag&&j==n+){
edge[i][n+]=a[i][];
}
else if(flag){
edge[i][j]=min(a[i][],a[j][]);
} }
} int total=EK();
printf("%d ",total);
int cnt=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(flow[i][j]>)
cnt++;
}
}
printf("%d\n",cnt);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(flow[i][j]>){
printf("%d %d %d\n",i,j,flow[i][j]);
}
}
} }
return ;
}
 
 
 
 
 
 

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 网络流拆点+路径还原

    http://poj.org/problem?id=3436 每台电脑有$p$个组成部分,有$n$个工厂加工电脑. 每个工厂对于进入工厂的半成品的每个组成部分都有要求,由$p$个数字描述,0代表这个部 ...

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

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

  4. POJ - 3436 ACM Computer Factory 网络流

    POJ-3436:http://poj.org/problem?id=3436 题意 组配计算机,每个机器的能力为x,只能处理一定条件的计算机,能输出特定的计算机配置.进去的要求有1,进来的计算机这个 ...

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

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

  6. POJ 2391 Ombrophobic Bovines ( 经典最大流 && Floyd && 二分 && 拆点建图)

    题意 : 给出一些牛棚,每个牛棚都原本都有一些牛但是每个牛棚可以容纳的牛都是有限的,现在给出一些路与路的花费和牛棚拥有的牛和可以容纳牛的数量,要求最短能在多少时间内使得每头牛都有安身的牛棚.( 这里注 ...

  7. POJ 1149 PIGS ★(经典网络流构图)

    [题意] 有M个猪圈,每个猪圈里初始时有若干头猪.一开始所有猪圈都是关闭的.依 次来了N个顾客,每个顾客分别会打开指定的几个猪圈,从中买若干头猪.每 个顾客分别都有他能够买的数量的上限.每个顾客走后, ...

  8. poj 1149经典网络流构图

    题意:m个猪圈,n个客户,每个客户给出选则猪圈的钥匙和需要购买猪的个数,其中每次客户购买时客户选则的猪圈数量可以相互更换,问最大购买数量. 思路:以客户作为除源点汇点之外的点,然后对于每个猪圈从源点连 ...

  9. 网络流相关知识点以及题目//POJ1273 POJ 3436 POJ2112 POJ 1149

    首先来认识一下网络流中最大流的问题 给定一个有向图G=(V,E),把图中的边看做成管道,边权看做成每根管道能通过的最大流量(容量),给定源点s和汇点t,在源点有一个水源,在汇点有一个蓄水池,问s-t的 ...

随机推荐

  1. ES6 extends继承及super使用读书笔记

    extends 继承 extends 实现子类的继承 super() 表示父类的构造函数, 子类必须在 constructor中调用父类的方法,负责会报错. 子类的 this 是父类构造出来的, 再在 ...

  2. jq weui 图片浏览器Photo Browser 第一次点击任意图片总是显示第一张

    第一次做这个图片浏览器的时候遇到一个问题,如共有6张图片,每次进入页面时,第一次点击,无论去点击6张图片的哪一张初始化显示的都是第一张图片.后面的每次点击都没有问题的. for(let i = 0;i ...

  3. 【杂题总汇】UVa-1336 Fixing the Great Wall

    [UVA-1336]Fixing the Great Wall 一开始把题看错了……直接用的整数存储答案:之后用double存最后输出答案的时候取整就AC了

  4. JS - 把类似document.querySelectorAll(".xxx")、document.getElementsByName("xxx")这种方法的返回结果转换成数组对象

    var btns = document.querySelectorAll(".btn");console.log(btns instanceof Array); // falseb ...

  5. Linux-日期时间相关命令

    获取当前时间 date [root@VM_0_3_centos ~]# date Mon Mar 18 19:13:33 CST 2019 [root@VM_0_3_centos ~]# date相关 ...

  6. 记一次微信小程序在安卓的白屏问题

    在做小程序的时候,做到了一个限时商品售卖,用到了倒计时,因为这个原因导致了安卓手机上使用小程序时,将小程序放入后台运行一段时间后,再次进入小程序后出现了页面白屏或者点击事件失效的情况,这里记录下 1. ...

  7. python--re(匹配字符串)

    \d 匹配任何十进制数:它相当于类 [0-9]. \D 匹配任何非数字字符:它相当于类 [^0-9]. \s 匹配任何空白字符:它相当于类 [ fv]. \S 匹配任何非空白字符:它相当于类 [^ f ...

  8. 使用file_get_contents()和curl()抓取网络资源的效率对比

    使用file_get_contents()和curl()抓取网络资源的效率对比 在将小程序用户头像合成海报的时候,用到了抓取用户头像对应的网络资源,那么抓取方式有很多,比如 file_get_cont ...

  9. Scala构建元数据

    反射方式构建元数据: 通过反射来获取RDD中的Schema信息.这种方式适合于列名(元数据)已知的情况下 步骤: 1.SparkConf配置环境 2.SparkContext初始化上下文 3.SQLC ...

  10. 学习python第十三天,函数5 装饰器decorator

    定义:装饰器本质是函数,(装饰其他函数)就是为其他函数添加附加功能原则:1.不能修改被装饰的函数的源代码 2.不能修改装饰的函数的调用方式 实现装饰器知识储备1函数即变量2.高阶函数,满足2个条件之一 ...