Help:=proc():print(`DoesNO(I1,I2),IsGood`(S)): print(`TotalW(S),ExonB(S)`): end: with(combinat): #IsGood(S): given a set of weighted intervals #{[a,b,w]} decides whether it is bad #IsGood(S): Is the set of weighted intervals S #such that no pairs overlap IsGood:=proc(S) local i,j: not member(false,{seq(seq(DoesNO(S[i],S[j]),i=j+1..nops(S)), j=1..nops(S)-1)}): end: #DoesO(I1,I2): do I1 and Is overlap? DoesNO:=proc(I1,I2) local i: evalb({seq(i,i=I1[1]..I1[2])} intersect {seq(i,i=I2[1]..I2[2])}={}): end: #ToatlW(S): the total weight of the set S TotalW:=proc(S) local i: add(S[i][3],i=1..nops(S)):end: #ExonB(S): the best subset of S of weighted intervals #followed by the value (record) ExonB:=proc(S) local T,champ,rec,cand,try1,i: rec:=-1: T:=powerset(S): for i from 1 to nops(T) do if IsGood(T[i]) then cand:=T[i]: try1:=TotalW(cand): if try1>rec then champ:=cand: rec:=try1: fi: fi: od: champ,rec: end: