根据某些约束来计算组合总数的算法
我有一些应该组合的字母。 该字母应在相应的地方合并,并选择省略一些字母。 例如,
对于A,我有A1,A2,A3。
对于B,我有B1,B2。
对于C,我有C1,C2,C3,C4。
对于D,我有D1,D2。
组合的一个例子是A1,B2,C1,D2。另一个可能的组合是_,b2,c1,d2(省略字母A)。
没有任何约束,总组合将为(3+1)(2+1)(4+1)(2+1)= 180组合。
但是,我想根据一些约束来计算总组合。 例如,基于[A1不能与B2一起出现]的约束,并且[A2不能与C4一起出现]总组合小于180。
我知道这可以通过包容性排斥原则来完成,但是这是非常困难的为了编程包含,排除计算。还有其他算法,而不是包容性排斥原则和蛮力吗?
非常感谢!!
I have some set of letters that should be combined.
The letter should be combined in corresponding places with a choice of omitting some letter.
For example,
For A, I have A1, A2, A3.
For B, I have B1, B2.
For C, I have C1, C2, C3, C4.
For D, I have D1, D2.
One example of the combination is A1,B2,C1,D2. Another possible combination is _,B2,C1,D2 (omitting letter A).
Without any constraints, the total combinations would be (3+1)(2+1)(4+1)(2+1) = 180 combinations.
However, I would like to count the total combinations based on some constraints.
For example, on the constraint that [A1 cannot occur together with B2] and [A2 cannot occur together with C4] the total combination would be less than 180.
I know this could be done with inclusion-exclusion principle, but it is quite difficult to program the inclusion, exclusion calculation. Is there any other algorithms rather than the inclusion-exclusion principle and brute force?
Thank you very much!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您高估了编码包容性排斥的努力。
I believe that you are overestimating the effort of coding inclusion-exclusion.