我有一个问题,我必须在嵌套哈希集中找到多个子集组合。基本上我有一个“主”嵌套哈希集,并且从“可能”嵌套哈希集的集合中,我必须以编程方式找到可能是“主”的同时子集的“可能”。
可以说我有以下内容:
var master = new HashSet<HashSet<string>>(new HashSet<string>[] {
new HashSet<string>( new string[] { "A", "B", "C"}),
new HashSet<string>( new string[] { "D", "E"}),
new HashSet<string>( new string[] { "F"})
}
);
var possible1 = new HashSet<HashSet<string>>(new HashSet<string>[] {
new HashSet<string>( new string[] { "A", "B", "C"}),
new HashSet<string>( new string[] { "F"})
}
);
var possible2 = new HashSet<HashSet<string>>(new HashSet<string>[] {
new HashSet<string>( new string[] { "D", "E"})
}
);
var possible3 = new HashSet<HashSet<string>>(new HashSet<string>[] {
new HashSet<string>( new string[] { "F"})
}
);
var possible4 = new HashSet<HashSet<string>>(new HashSet<string>[] {
new HashSet<string>( new string[] { "X", "Y", "Z"})
}
);
var possible5 = new HashSet<HashSet<string>>(new HashSet<string>[] {
new HashSet<string>( new string[] { "A", "B" }),
new HashSet<string>( new string[] { "D", "E"})
}
);
我应该从我的算法中得到的输出应该如下:
所有可能的组合子集:
possible1 and possible2
possible3 and possible5
possible2 and possible3
possible1
possible2
possible3
possible5
我正在尝试找出解决此问题的最佳方法。当然,还有蛮力选项,但如果可以的话,我会尽量避免这种情况。
我只希望我的问题足够清楚。
编辑
为了进一步详细说明什么构成子集,这里有一些例子,给定主 {{"A","B","C"},{"C","D","E",F"},{ "X","Y","Z"}} :
- {{"A","B"}{"C","D"}} 将是
- {{"A","B","C"},{"X","Y"}} 将是一个子集
- {{"A","B"},{"A","B"}} 不会是子集
- {{"A","B","C","D"}} 不会是子集
- {{"A","B","C"},{"C","D","X"}} 不会是子集
基本上每个子集都需要是 master 中相应子集的子集。