Example #1
0
void partitionDecreasing(int value)
{
  int *partition = malloc(sizeof(int) * value);
  partitionDecreasingHelper(value, partition, 0);
  free(partition);

}
Example #2
0
void partitionDecreasingHelper(int budget, int *partition, int pos)
{
  //BASE CASE!!!
  if (budget == 0){
    printpartition(partition, pos);
    return;
  }  

  //INDUCTIVE CASE!!!!!
  int spending;
  int begin = pos == 0 ? budget : partition[pos - 1] - 1;
  for(spending = begin; spending > 0 ; spending--){
    partition[pos] = spending;
    partitionDecreasingHelper(budget - spending, partition, pos + 1);
  }
}
Example #3
0
void partitionDecreasingHelper(int N, int * partition, int pos)
{
	//BASE CASE
	if(N == 0)
	{
	printPartition(partition, pos);
	return;
	}

	//INDUCTIVE CASE
	int i;
	int start = pos == 0 ? N : partition[pos - 1] - 1;
	for(i = start; i > 0; i--)
	{
	partition[pos] = i;
	partitionDecreasingHelper(N - i, partition, pos + 1);
	}
}