Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Problem05SubsetSums
- {
- static void Main()
- {
- short result = 0;
- long temp = 0;
- string combination = "";
- long s = long.Parse(Console.ReadLine());
- byte n = byte.Parse(Console.ReadLine());
- long[] numberN = new long[n];
- for (int i = 0; i < n; i++)
- {
- numberN[i] = long.Parse(Console.ReadLine());
- }
- for (int i = 1; i < Math.Pow(2, n); i++)
- {
- combination = Convert.ToString(i, 2).PadLeft(n, '0');
- temp = 0;
- for (int a = 0; a < combination.Length; a++)
- {
- if (combination[a] == '1')
- {
- temp = temp + numberN[a];
- }
- }
- if (temp == s)
- {
- result++;
- }
- }
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement