这其实是个线性规划问题,但是在数量不大的情况下,函数公式还可以解决,数据量大了后难度较大。
公式结果列举了所有可能的组合:
- =DROP(REDUCE("",UNIQUE(D2:D45),LAMBDA(XX,YY,VSTACK(XX,LET(Rc,FILTER(J2:K45,D2:D45=YY),sRc,TAKE(Rc,,1),n,ROWS(sRc),nMax,DEC2HEX(2^n-SEQUENCE(2^n),9),Res,--MID(RIGHT(HEX2BIN(LEFT(nMax,1),4)&HEX2BIN(MID(nMax,2,2),8)&HEX2BIN(MID(nMax,4,2),8)&HEX2BIN(MID(nMax,6,2),8)&HEX2BIN(RIGHT(nMax,2),8),n),TOROW(SEQUENCE(n)),1),sBox,MMULT(Res,sRc),sSel,FILTER(Res,sBox=-INDEX(TAKE(Rc,,-1),1)),sCom,BYROW(sSel,LAMBDA(x,TEXTJOIN(",",1,IF(x=1,TRANSPOSE(sRc),"")))),Rst,IFERROR(sCom,"无匹配"),IFNA(HSTACK(YY,Rst),""))))),1)
复制代码 |