Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Subset
- {
- static void Main()
- {
- long s = long.Parse(Console.ReadLine());
- byte n = byte.Parse(Console.ReadLine());
- long[] numbers = new long[n+1];
- long currentSum = 0;
- int answer = 0;
- for (int i = 1; i <= n; i++)
- numbers[i] = long.Parse(Console.ReadLine());
- int max = (int)Math.Pow(2, n) - 1;
- for (int i = 1; i <= max; i++)
- {
- currentSum = 0;
- for (int j = 1; j <= n; j++)
- if (((i >> (j - 1)) & 1) == 1)
- currentSum += numbers[j];
- if (currentSum == s)
- answer++;
- }
- Console.WriteLine(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement