Generating Permutations using LINQ

后端 未结 8 1981
我寻月下人不归
我寻月下人不归 2020-12-01 04:59

I have a set of products that must be scheduled. There are P products each indexed from 1 to P. Each product can be scheduled into a time period 0 to T. I need to construct

8条回答
  •  死守一世寂寞
    2020-12-01 05:18

        public static IList> Permutation(ImmutableList> dimensions)
        {
            IList> result = new List>();
            Step(ImmutableList.Create(), dimensions, result);
            return result;
        }
    
        private static void Step(ImmutableList previous, 
            ImmutableList> rest, 
            IList> result)
        {
            if (rest.IsEmpty)
            {
                result.Add(previous);
                return;
            }
    
            var first = rest[0];
            rest = rest.RemoveAt(0);
    
            foreach (var label in first)
            {
                Step(previous.Add(label), rest, result);
            }
        }
    

提交回复
热议问题