Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. //
  2. //  2pow.c
  3. //  
  4. //
  5. //  Created by MacBook return 0; on 26.11.14.
  6. //
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. int pow2(int a)
  13. {
  14.     int count = 0;
  15.     if ((a & (a - 1)) || (a == 0)) {
  16.         return 0;
  17.     } else {
  18.         return 1;
  19.     }
  20. }
  21.  
  22. void Comb(int m, int nel, int *P)
  23. {
  24.     int count = 0;
  25.     CombRec(m, 0, nel, 0, P);
  26. }
  27.  
  28. void CombRec(int m, int sum, int nel, int i, int *P)
  29. {
  30.     int j, count = 0;
  31.     if (m == 0) {
  32.         if (pow2(sum)) {
  33.             count++;
  34.             sum = 0;
  35.         }
  36.     } else {
  37.         for (j = i; j < nel; j++) {
  38.             if (m + j - 1 >= nel) {
  39.                 break;
  40.             }
  41.             j++;
  42.             CombRec(m - 1, sum + P[j], nel, i, P);
  43.         }
  44.     }
  45. }
  46.  
  47. int main()
  48. {
  49.     int *P;
  50.     int i, j, k, nel, count = 0;
  51.     scanf("%d", &nel);
  52.     P = (int*)malloc(nel * sizeof(int));
  53.     for (i = 0; i < nel; i++) {
  54.         scanf("%d", P + i);
  55.     }
  56.     for (i = 1; i <= nel; i++) {
  57.         Comb(i, nel, P);
  58.     }
  59.     printf("%d", count);
  60.     free(P);
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement