0
我的INT <List<List<int>>
列表的列表的列表,它代表一個方向矢量算法函數,載體
例如
(1,2)
(1,3)
(2,4)
(3,5)
(4,3)
(5,1)
創造一切可能的組合,我想創造一切可能的途徑與使最終的路由不創建的環形圈的那些載體(在其自身上的兩端)
這樣:
(1,2)
(1,3)
(2,4)
(3,5)
(4,3)
(5,1)
(1,2,4)
(1,2,4,3)
(1,2,4,3,5)
(1,2,4,3,5,1)
(1,3,5)
(1,3,5,1)
(2,4,3)
(2,4,3,5)
(2,4,3,5,1)
(2,4,3,5,1,2)
(3,5,1)
etc...
我還沒有找到一個有效的方法來做這樣的事情。
我以前已經嘗試過使用
private IEnumerable<int> constructSetFromBits(int i)
{
for (int n = 0; i != 0; i /= 2, n++)
{
if ((i & 1) != 0)
yield return n;
}
}
public IEnumerable<List<T>> ProduceWithRecursion(List<T> allValues)
{
for (var i = 0; i < (1 << allValues.Count); i++)
{
yield return ConstructSetFromBits(i).Select(n => allValues[n]).ToList();
}
}
它運作良好,但忽略了這個問題的方向方面創造所有可能的組合。
的方法並不一定是遞歸的,雖然我懷疑這可能是去做
謝謝!看起來比我所做的更好...... 我會試試看,然後我會據此解決 – Nick