1
0

subsetSum.c 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <pthread.h>
  4. #include <math.h>
  5. #include "pa13.h"
  6. #define SUCCESS 0
  7. #define FAILURE -1
  8. /*
  9. * Write a parallel C program that returns the answer for the following problem:
  10. * Given a nonempty set S, with elements {a1, a2, a3, ...}, and a integer N,
  11. * find the number of nonempty subsets of S, such that the sum of all elements
  12. * in this subset equals to N.
  13. *
  14. * Arguments:
  15. * intset - pointer to an array of a integer set
  16. * length - size (length) of the integer set
  17. * N - target sum value
  18. * numThread - number of threads
  19. * Return value:
  20. * numOfSolutions - Number of nonempty subsets in which the subsetSum value
  21. * matches with N. This variable should be protected as the critical
  22. * sections by using mutex objects.
  23. *
  24. * Hint: The total number of possible subsets is (2^(length)-1). You may use
  25. * math library function 'pow()' to assign the index for each thread.
  26. * pthread.h and math.h are already included in this file.
  27. */
  28. int subsetSum(int * intset, int length, int N, int numThread)
  29. {
  30. }