예제 #1
0
            internal TmpPartition add(int a)
            {
                TmpPartition result = new TmpPartition();

                result.remainder = remainder - a;
                result.partition = new List <int>();
                result.partition.AddRange(partition);
                result.partition.Add(a);
                return(result);
            }
예제 #2
0
 private static void Partition(TmpPartition x, ICollection <int[]> allPartitions, int len)
 {
     if (x.remainder == 0 && x.partition.Count == len)
     {
         allPartitions.Add(x.partition.ToArray());
         return;
     }
     if (x.partition.Count == len)
     {
         return;
     }
     for (int i = 0; i <= x.remainder; i++)
     {
         Partition(x.add(i), allPartitions, len);
     }
 }
예제 #3
0
 internal TmpPartition Add(int a)
 {
     TmpPartition result = new TmpPartition{remainder = remainder - a, partition = new List<int>()};
     result.partition.AddRange(partition);
     result.partition.Add(a);
     return result;
 }
예제 #4
0
        private static void Partition(TmpPartition x, ICollection<int[]> allPartitions, int len,
			Func<int[], bool> validPartition, Action<int[]> task)
        {
            if (x.remainder == 0 && x.partition.Count == len){
                int[] part = x.partition.ToArray();
                if (validPartition == null || validPartition(part)){
                    if (task != null){
                        task(part);
                    } else{
                        allPartitions.Add(part);
                    }
                }
                return;
            }
            if (x.partition.Count == len){
                return;
            }
            for (int i = 0; i <= x.remainder; i++){
                Partition(x.Add(i), allPartitions, len, validPartition, task);
            }
        }