Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. class Subset
  4. {
  5. static void Main()
  6. {
  7. long s = long.Parse(Console.ReadLine());
  8. byte n = byte.Parse(Console.ReadLine());
  9. long[] numbers = new long[n+1];
  10. long currentSum = 0;
  11. int answer = 0;
  12.  
  13. for (int i = 1; i <= n; i++)
  14. numbers[i] = long.Parse(Console.ReadLine());
  15.  
  16. int max = (int)Math.Pow(2, n) - 1;
  17.  
  18. for (int i = 1; i <= max; i++)
  19. {
  20. currentSum = 0;
  21. for (int j = 1; j <= n; j++)
  22. if (((i >> (j - 1)) & 1) == 1)
  23. currentSum += numbers[j];
  24.  
  25. if (currentSum == s)
  26. answer++;
  27. }
  28. Console.WriteLine(answer);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement