Tag: Code size overrides memset break bool capacity and Dinic
Given n-weighted open intervals, the first interval coverage interval (AI,BI), the weight value is WI. It is now required to pick out some intervals to maximize the total weight and to satisfy any point on the real axis to be overwritten no more than k times.
1<=k<=n<=200.1<=ai<bi<=100000.1<=wi<=100000.
Minimum cost maximum flow.
Discretization of all interval endpoints to integers 1 to m, each corresponding to a point.
The source point is connected to an integer 1 point with an edge with a capacity of K cost of 0.
An integer i point to an integer i+1 point with an edge that has a positive infinity charge of 0. (1<=i<m).
An integer m point is connected to a meeting point with an edge that has a positive infinity charge of 0.
Each interval is connected by a AAI point to a bbi point with a capacity of 1-wi (AAI and bbi are the values of the interval left and right end points).
The minimum cost maximum flow counter is the answer.
Consider for a aai to the edge of the BBI, the cost of negative is necessarily preferred, so that the interval (Aai,bbi) residual traffic minus one, the corresponding problem (AI,BI) The point of the remaining number of coverage minus one. It is noted that the interval of the subject is open, so the two-interval connection does not affect the result.
1#include <cstring>2#include <cstdio>3#include <algorithm>4#include <iostream>5#include <queue>6 using namespacestd;7 Const intdian=405;8 Const intbian=1505;9 Const intinf=0x3f3f3f3f;Ten intZkh[dian],ykh[dian],khqz[dian]; One intZl[dian],yl[dian]; A intH[dian],nxt[bian],ver[bian],val[bian],cos[bian],minn[dian],with[dian]; - intV[dian],d[dian]; - intN,k,tot,bula; the ints,t; - voidAddintAintBintCintd) { -tot++;ver[tot]=b;val[tot]=c;cos[tot]=d;nxt[tot]=h[a];h[a]=tot; -tot++;ver[tot]=a;val[tot]=0; cos[tot]=-d;nxt[tot]=h[b];h[b]=tot; + } - BOOLTell () { +memset (V,0,sizeof(v)); Amemset (D,0x3f,sizeof(d)); atMemset (with,0,sizeof(with)); -MEMSET (Minn,0x3f,sizeof(Minn)); -queue<int>Q; - Q.push (S); -v[s]=1; -d[s]=0; in while(!Q.empty ()) { - intx=Q.front (); to Q.pop (); +v[x]=0; - for(intI=h[x];i;i=Nxt[i]) { the inty=Ver[i]; * if(d[y]>d[x]+cos[i]&&Val[i]) { $d[y]=d[x]+Cos[i];Panax Notoginsengminn[y]=min (minn[x],val[i]); -with[y]=i; the if(!V[y]) { +v[y]=1; A Q.push (y); the } + } - } $ } $ if(d[t]==0x3f3f3f3f) - return 0; - return 1; the } - intZeng () {Wuyi for(inti=t;i!=s;i=ver[with[i]^1]){ theval[with[i]]-=Minn[t]; -val[with[i]^1]+=Minn[t]; Wu } - returnminn[t]*D[t]; About } $ intDinic_cost () { - intR=0; - while(Tell ()) -r+=Zeng (); A returnR; + } the intMain () { - intCAs; $scanf"%d",&CAs); the while(cas--){ thememset (H,0,sizeof(h)); thememset (NXT,0,sizeof(NXT)); thetot=1; -Bula=0; inscanf"%d%d",&n,&k); the for(intI=1; i<=n;i++) thescanf"%d%d%d",&zkh[i],&ykh[i],&khqz[i]); About //I am too konjac konjac, the following large paragraph while statement (discretization) unintelligible, it is recommended to skip. the intHHD; the while(1){ theHhd=INF; + for(intI=1; i<=n;i++) - if(hhd>Zkh[i]) theHhd=Zkh[i];Bayi if(hhd==INF) the Break; thebula++; - for(intI=1; i<=n;i++) - if(hhd==Zkh[i]) { the if(ykh[i]==INF) { thezkh[i]=INF; theyl[i]=Bula; the } - Else{ thezkh[i]=Ykh[i]; theykh[i]=INF; thezl[i]=Bula;94 } the } the } thes=bula+1, t=bula+2;98 for(intI=1; i<bula;i++) AboutAdd (i,i+1Inf0); -Add (S,1K0);101Add (Bula,t,inf,0);102 for(intI=1; i<=n;i++)103Add (Zl[i],yl[i],1,-khqz[i]);104printf"%d\n",-dinic_cost ()); the }106 return 0;107}
POJ 3680 Intervals