Esempio n. 1
0
void partitionIncreasing(int value)
{
  int *partition = malloc(sizeof(int) * value);
  partitionIncreasingHelper(value, partition, 0);
  free(partition);

}
Esempio n. 2
0
void partitionIncreasingHelper(int budget, int *partition, int pos)
{
  //BASE CASE!!!
  if (budget == 0){
    printpartition(partition, pos);
    return;
  }  

  //INDUCTIVE CASE!!!!!
  int spending;
  int begin = pos == 0 ? 1 : partition[pos - 1] + 1;
  for(spending = begin; spending <= budget; spending++){
    partition[pos] = spending;
    partitionIncreasingHelper(budget - spending, partition, pos + 1);
  }
}
Esempio n. 3
0
void partitionIncreasingHelper(int N, int * partition, int pos)
{
	//BASE CASE
	if(N == 0)
	{printPartition(partition, pos);
	return;
	}

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