Test instructions
T Company found that its development of a software has n errors, and then issued a batch of the software a total of M patch
Order. Each patch has its own specific environment, a patch that contains only some errors in the software and
Can only be used if no other errors are included. A patch often adds other errors while excluding certain errors.
In other words, for each patch I, there are 2 corresponding error sets B1[i] and b2[i], so that only if the software
You can use patch I if you include all errors in b1[i] without any errors in b2[i]. Patch I will fix
Some errors in the software f1[i], while adding some other error f2[i]. In addition, each patch takes a certain amount of time.
Try to design an algorithm, using T company provided by the M patch program to repair the original software into a bug-free soft
And make the repaired software take the least time.
Input File Example
Input.txt
3 3
1 000 00-
1 00-0-+
2 0---+ +
Output File Example
Output.txt
8
Analysis
SM Network Flow 24 questions, how all the questions have.
Obviously is a shortest way, on the SPFA is good ...
Minimum transfer cost, but no constraints, so no flow, direct costs ran over.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7#include <cmath>8#include <map>9 using namespacestd;Ten #defineMAXM 110 One #defineMAXN 1100000 A #defineINF 0XFFFFFFF - - intW[MAXM],B1[MAXM],B2[MAXM],F1[MAXM],F2[MAXM]; the - intDIS[MAXN]; - BOOLINQ[MAXN]; -queue<int>Q; + intst,ed,n,m; - + voidSPFA () A { at while(!q.empty ()) Q.pop (); -memset (DIS, the,sizeof(DIS)); -memset (INQ,0,sizeof(INQ)); -Q.push (ST);d is[st]=0; inq[st]=1; - while(!q.empty ()) - { in intx=Q.front (); - for(intI=1; i<=m;i++)if((X&b1[i]) ==b1[i]&& (x&b2[i]) = =0) to { + inty=x-(x&f1[i]); -y|=F2[i]; the if(dis[y]>dis[x]+W[i]) * { $dis[y]=dis[x]+W[i];Panax Notoginseng if(!Inq[y]) - { the Q.push (y); +inq[y]=1; A } the } + } -Q.pop (); inq[x]=0; $ } $ } - - Chars[ -]; the intMain () - {Wuyiscanf"%d%d",&n,&m); the for(intI=1; i<=m;i++) - { Wuscanf"%d",&w[i]); -scanf"%s", s); Aboutb1[i]=b2[i]=f1[i]=f2[i]=0; $ for(intj=0; j<n;j++) - if(s[j]=='+') b1[i]+=1<<J; - Else if(s[j]=='-') b2[i]+=1<<J; -scanf"%s", s); A for(intj=0; j<n;j++) + if(s[j]=='-') f1[i]+=1<<J; the Else if(s[j]=='+') f2[i]+=1<<J; - } $St= (1<<n)-1; ed=0; the SPFA (); the if(dis[ed]>=inf-100000) printf ("0\n"); the Elseprintf"%d\n", dis[ed]); the return 0; -}
View Code
2016-11-04 20:24:58
"Network Flow 24 questions" No.12 software patch problem (minimum transfer cost shortest)