Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace Algorithm
{
Class full combination algorithm
{
[Flags]
Public enum PersonType
{
Audit = 1,
Child = 2,
Senior = 4
}
Public static void Run (string [] args)
{
Var lstSource = GetEnumList <PersonType> ();
Var lstComb = FullCombination (lstSource );
Var lstResult = new List <PersonType> ();
LstComb. ForEach (item =>
{
LstResult. Add (item. Aggregate (result, source) => result | source ));
});
}
Public static List <T> GetEnumList <T> ()
{
Var lst = new List <T> ();
Foreach (T item in Enum. GetValues (typeof (T )))
{
Lst. Add (item );
}
Return lst;
}
// Full combination algorithm
Public static List <T> FullCombination <T> (List <T> lstSource)
{
Var n = lstSource. Count;
Var max = 1 <n;
Var lstResult = new List <T> ();
For (var I = 0; I <max; I ++)
{
Var lstTemp = new List <T> ();
For (var j = 0; j <n; j ++)
{
If (I> j & 1)> 0)
{
LstTemp. Add (lstSource [j]);
}
}
LstResult. Add (lstTemp );
}
LstResult. RemoveAt (0 );
Return lstResult;
}
}
}