Guest User

Untitled

a guest
Nov 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6.  
  7. int polje[21];
  8.  
  9. int main()
  10. {
  11.     int t, i, n, m, brn, rj, j, k, komb, sum;
  12.     scanf ("%d", &t);
  13.     for (i = 0; i < t; i++){
  14.         brn = 0;
  15.         rj = 0;
  16.         scanf ("%d %d", &n, &m);
  17.         for (j = 0; j < n; j++){
  18.             scanf ("%d", &polje[brn]);
  19.             if (polje[brn] <= m)
  20.                 brn++;
  21.         }
  22.         komb = pow (2, brn);
  23.         for (j = 1; j < komb; j++){
  24.             sum = 0;
  25.             for (k = 0; k < brn; k++){
  26.                 if (j & 1 << k) sum += polje[k];  
  27.             }    
  28.             if (sum == m){
  29.                 rj = 1;
  30.                 break;
  31.             }
  32.         }
  33.         if (rj == 0)
  34.             printf ("No\n");
  35.         else
  36.             printf ("Yes\n");
  37.     }
  38.     return 0;
  39. }
Add Comment
Please, Sign In to add comment