poj 3436 ACM Computer Factory

ACM Computer Factory
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6912 Accepted: 2448 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 jDi,k — output specification for part k.

Constraints

1 ≤ P ≤ 10, 1 ≤ ≤ 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

提示

题意:

题目太长这里简化以下

ACM比赛电脑的配置可以说是一个模子里打造出来的,现在电脑比较少,需要用比较少的时间来制造足够多的电脑。有n(1<=n<=50)个机器,每一台可以一次组装q(1<=q<=10000)台电脑,每台电脑有p(1<=p<=10)个零件,但机器只能组装部分零件。请设计一套算法来保证每经过一次生产线最多有几台电脑可以完成组装。(机器不一定要全部用上)

机器对应的状态如下:

组装前

0:这个部件没有才能处理。

1:这个部件有才能处理。

2:有没有都无所谓了。

组装后:

0:这个部件依然缺着。

1:这个部件已组装完成。

思路:

把每个机器的关系用图存下来再套匈牙利就完了,别忘了还有走过路线的输出。(来源)

示例程序

Source Code

Problem: 3436		Code Length: 2847B
Memory: 412K		Time: 16MS
Language: GCC		Result: Accepted
#include <stdio.h>
#include <string.h>
struct
{
    int ain[10],aout[10],aq;
}a[50];
int map[52][52],p[52],map1[52][52];
int bfs(int ln)
{
    int q[4000],i,f=0,top=0;
    memset(p,-1,sizeof(p));
    p[0]=0;
    q[top]=0;
    top++;
    while(f<top)
    {
        for(i=0;ln>=i;i++)
        {
            if(p[i]==-1&&map[q[f]][i]>0)
            {
                p[i]=q[f];
                if(i==ln)
                {
                    return 1;
                }
                q[top]=i;
                top++;
            }
        }
        f++;
    }
    return 0;
}
int maxf(int ln)
{
    int i,max=0,min;
    while(bfs(ln)==1)
    {
        min=1000000007;
        for(i=ln;i!=0;i=p[i])
        {
            if(min>map[p[i]][i])
            {
                min=map[p[i]][i];
            }
        }
        for(i=ln;i!=0;i=p[i])
        {
            map[p[i]][i]=map[p[i]][i]-min;
            map[i][p[i]]=map[i][p[i]]+min;
        }
        max=max+min;
    }
    return max;
}
int main()
{
    int n,p,q,i,i1,i2,s,t,max,num,d[52][3];
    memset(map,0,sizeof(map));
    scanf("%d %d",&p,&n);
    for(i=1;n>=i;i++)
    {
        scanf("%d",&a[i].aq);
        for(i1=0;p>i1;i1++)
        {
            scanf("%d",&a[i].ain[i1]);
        }
        for(i1=0;p>i1;i1++)
        {
            scanf("%d",&a[i].aout[i1]);
        }
    }
    for(i=1;n>=i;i++)
    {
        s=1;
        t=1;
        for(i1=0;p>i1;i1++)
        {
            if(a[i].ain[i1]==1)		//是否为源点
            {
                s=0;
            }
            if(a[i].aout[i1]==0)	//是否为汇点
            {
                t=0;
            }
        }
        if(s==1)		//我们设0点为最终源点
        {
            map[0][i]=a[i].aq;
        }
        if(t==1)		//我们设n+1点为最终源点
        {
            map[i][n+1]=a[i].aq;
        }
        for(i1=1;n>=i1;i1++)		//存下其他通路
        {
            if(i!=i1)
            {
                for(i2=0;p>i2;i2++)
                {
                    if(a[i].aout[i2]+a[i1].ain[i2]==1)
                    {
                            break;
                    }
                }
                if(i2==p)
                {
                    if(a[i].aq<a[i1].aq)
                    {
                        map[i][i1]=a[i].aq;
                    }
                    else
                    {
                        map[i][i1]=a[i1].aq;
                    }
                }
            }
        }
    }
    memcpy(map1,map,sizeof(map));		//需要输出走过的路径,所以为了判断对图要进行备份
    max=maxf(n+1);
    num=0;
    for(i=1;n>=i;i++)
    {
        for(i1=1;n>=i1;i1++)
        {
            if(map1[i][i1]>map[i][i1])			//如果走过,那么图的最终状态一定要比之前的要小
            {
                d[num][0]=i;
                d[num][1]=i1;
                d[num][2]=map1[i][i1]-map[i][i1];
                num++;
            }
        }
    }
    printf("%d %d\n",max,num);
    for(i=0;num>i;i++)
    {
        printf("%d %d %d\n",d[i][0],d[i][1],d[i][2]);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值