Description
Analysis
Is not a look like what network streamline planning and so on.
However, there is no train of thought, a violent, plus pruning but run fast
Plot, toy for edge, shop for Point
Search for the selected points, then one side of the two points of the link must have an election
Plus some feasibility, optimal pruning
The complexity is said to be O (Fibonacci (40)). Code
by Alan_cty (ORZ)
#include <cstdio> #include <cstring> #include <algorithm> #define FO (i,a,b) for (int i=a;i<=b;i++) #
Define REP (i,a) for (int i=last[a];i;i=next[i]) using namespace std;
const int m=45,n=105;
int n,m,k,a,b,c,d,l,sum,ans,tot,val[m],bz[m];
int last[m],next[n*2],t[n*2],v[n*2]; void Add (int x,int y,int z) {t[++l]=y;v[l]=z;next[l]=last[x];last[x]=l;} void dfs (int x,int y,int z) {if (y>
k) return;
if (y+m-x+1<k) return;
if (Z>=ans) return;
if (x>m) {ans=z;
Return
} if (Bz[x]) DFS (X+1,Y,Z);
else {rep (i,x) {if (!bz[t[i]]) y++;
bz[t[i]]++;
Z+=v[i];
} bz[x]=0;
DFS (x+1,y,z+val[x]);
Rep (i,x) {if (bz[t[i]]==1) y--;
bz[t[i]]--;
Z-=v[i];
} bz[x]=1;
DFS (X+1,Y+1,Z);
bz[x]=0;
}} int main () {freopen ("toy.in", "R", stdin);
Freopen ("Toy.out", "w", stdout); scanf ("%d%d%d ", &n,&m,&k);
Fo (i,1,n) {scanf ("%d%d%d%d", &a,&b,&c,&d);
if (a==c) {sum+=min (b,d);
if (!bz[a]) tot++;
bz[a]++;
Continue
} if (a>c) swap (a,c), swap (B,D);
Add (A,c,max (d-b,0));
Val[c]+=max (b-d,0);
Sum+=min (B,D);
} ans=0x7fffffff;
DFS (1,tot,0);
printf ("%d\n", Sum+ans); }