(最大流+拆点+无源点汇点)ACM Computer Factory

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.
题目大意是ACM竞赛用的电脑在生产时需要安装多个零件,而工厂有多个安装零件的加工机器,每个机器在加工前对这个电脑有一定要求,可能需要这个电脑已经安装好某个零件,可能需要这个电脑没安装这个零件,也可能装不装这个零件都没有影响。每个机器会说明加工完后的电脑的零件配备情况,当所有零件都安装完毕时,电脑就能投入使用。而每个加工机器都有他的工作性能(以计算机每小时为单位),题目求一个工厂的最大整体性能
首先题目没有设置源点和汇点,所以需要自行设置超级源点和超级汇点。
将加工机器视为一个点,则这些点带有权值,因此需要拆点。
将超级源点连接零件要求只有0或2的点,将超级汇点连接电脑加工完成的点(即产出全为1的点),然后跑最大流

#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=10000+5;
const int maxm=100000+5;
int head[maxn],dis[maxn],ne,n,m,S,T,ans,a1[maxn],b1[maxn],c1[maxn];
struct node
{
	int in[11],out[11];
	int in1,out1;
	int flow;
}a[maxn];
void init()
{
	ans=0;
	ne=0;
	memset(head,-1,sizeof(head));
}
struct edge{int v,w,nxt,ws,us;}G[maxm<<1];
void add(int u,int v,int w)
{
	G[ne]=(edge){v,w,head[u],w,u};
	head[u]=ne++;
	G[ne]=(edge){u,0,head[v],0,v};
	head[v]=ne++;
}
int bfs()
{
	memset(dis,-1,sizeof(dis));
	queue<int> q;
	q.push(S);
	dis[S]=0;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=head[u];i!=-1;i=G[i].nxt)
		{
			int v=G[i].v;
			if(dis[v]==-1&&G[i].w>0)
			{
				dis[v]=dis[u]+1;
				q.push(v);
			}
		}
	}
	return dis[T]!=-1;
}
int dfs(int u,int exp)
{
	if(u==T) return exp;
	int flow=0,tmp=0;
	for(int i=head[u];i!=-1;i=G[i].nxt)
	{
		int v=G[i].v;
		if(dis[v]==dis[u]+1&&G[i].w>0)
		{
			tmp=dfs(v,min(G[i].w,exp));
			if(!tmp) continue;
			exp-=tmp;
			flow+=tmp;
			G[i].w-=tmp;
			G[i^1].w+=tmp;
			if(!exp) break;
		}
	}
	return flow;
}
int main()
{
	
	while(~scanf("%d%d",&n,&m))
	{
		init();
		T=m*2+1;
		S=0;
		for(int i=1;i<=m;i++)
		{
			scanf("%d",&a[i].flow);
			add(i,i+m,a[i].flow);
			a[i].in1=0;
			for(int j=0;j<n;j++)
			{
				scanf("%d",&a[i].in[j]);
				if(a[i].in[j]==1) a[i].in1++;
			}
			a[i].out1=0;
			for(int j=0;j<n;j++)
			{
				scanf("%d",&a[i].out[j]);
				if(a[i].out[j]==0) a[i].out1++;
			}
		}
		for(int i=1;i<=m;i++)
		{
			if(a[i].in1==0) add(0,i,inf);
			if(a[i].out1==0) add(i+m,T,inf);
			for(int j=1;j<i;j++)
			{
				int flag=0;
				for(int k=0;k<n;k++)
				{
					if(a[j].out[k]+a[i].in[k]==1)
					{
						flag=1;
						break;
					}
				}
				if(!flag) add(j+m,i,inf);
				flag=0;
				for(int k=0;k<n;k++)
				{
					if(a[j].in[k]+a[i].out[k]==1)
					{
						flag=1;
						break;
					}
				}
				if(!flag) add(i+m,j,inf);
			}
		}
		while(bfs())
		{
			ans+=dfs(S,inf);
		}
		int x=0;
		for(int i=m*2;i<ne;i++)
		{
			if(G[i].ws>G[i].w&&G[i].us-m>0&&G[i].v!=2*m+1)
			{
				a1[x]=G[i].us-m;
				b1[x]=G[i].v;
				c1[x]=G[i].ws-G[i].w;
				x++;
			}
		}
		printf("%d %d\n",ans,x);
		for(int i=0;i<x;i++)
		{
			printf("%d %d %d\n",a1[i],b1[i],c1[i]);
		}
	}
	
}
内容概要:本文档围绕六自由度机械臂的ANN人工神经网络设计展开,涵盖正向与逆向运动学求解、正向动力学控制,并采用拉格朗日-欧拉法推导逆向动力学方程,所有内容均通过Matlab代码实现。同时结合RRT路径规划与B样条优化技术,提升机械臂运动轨迹的合理性与平滑性。文中还涉及多种先进算法与仿真技术的应用,如状态估计中的UKF、AUKF、EKF等滤波方法,以及PINN、INN、CNN-LSTM等神经网络模型在工程问题中的建模与求解,展示了Matlab在机器人控制、智能算法与系统仿真中的强大能力。; 适合人群:具备一定Ma六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)tlab编程基础,从事机器人控制、自动化、智能制造、人工智能等相关领域的科研人员及研究生;熟悉运动学、动力学建模或对神经网络在控制系统中应用感兴趣的工程技术人员。; 使用场景及目标:①实现六自由度机械臂的精确运动学与动力学建模;②利用人工神经网络解决传统解析方法难以处理的非线性控制问题;③结合路径规划与轨迹优化提升机械臂作业效率;④掌握基于Matlab的状态估计、数据融合与智能算法仿真方法; 阅读建议:建议结合提供的Matlab代码进行实践操作,重理解运动学建模与神经网络控制的设计流程,关注算法实现细节与仿真结果分析,同时参考文中提及的多种优化与估计方法拓展研究思路。
内容概要:本文围绕电力系统状态估计中的异常检测与分类展开,重介绍基于Matlab代码实现的相关算法与仿真方法。文章详细阐述了在状态估计过程中如何识别和分类量测数据中的异常值,如坏数据、拓扑错误和参数误差等,采用包括残差分析、加权最小二乘法(WLS)、标准化残差检测等多种经典与现代检测手段,并结合实际算例验证方法的有效性。同时,文档提及多种状态估计算法如UKF、AUKF、EUKF等在负荷突变等动态场景下的应用,强调异常处理对提升电力系统运行可靠性与安全性的重要意义。; 适合人群:具备电力系统基础知识和一定Matlab编程能力的高校研究生、科研人员及从事电力系【状态估计】电力系统状态估计中的异常检测与分类(Matlab代码实现)统自动化相关工作的工程技术人员。; 使用场景及目标:①掌握电力系统状态估计中异常数据的产生机制与分类方法;②学习并实现主流异常检测算法,提升对状态估计鲁棒性的理解与仿真能力;③服务于科研项目、课程设计或实际工程中的数据质量分析环节; 阅读建议:建议结合文中提供的Matlab代码进行实践操作,配合电力系统状态估计的基本理论进行深入理解,重关注异常检测流程的设计逻辑与不同算法的性能对比,宜从简单案例入手逐步过渡到复杂系统仿真。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值