Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class SubsetSums
- {
- static void Main(string[] args)
- {
- //80 tochki
- long s = long.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- long[] numbers = new long[n];
- long sum = 0;
- int subsetsCount = 0;
- for (int i = 0; i < n; i++)
- {
- numbers[i] = long.Parse(Console.ReadLine());
- }
- if (n >= 1)
- {
- for (int i = 0; i < n; i++)
- {
- sum = numbers[i];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- if (n >= 2)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- sum = numbers[i] + numbers[j];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 3)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- sum = numbers[i] + numbers[j] + numbers[k];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 4)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 5)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 6)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 7)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 8)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 9)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 10)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 11)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- for (int z = y + 1; z < n; z++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y] + numbers[z];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 12)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- for (int z = y + 1; z < n; z++)
- {
- for (int a = z + 1; a < n; a++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y] + numbers[z] + numbers[a];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 13)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- for (int z = y + 1; z < n; z++)
- {
- for (int a = z + 1; a < n; a++)
- {
- for (int b = a + 1; b < n; b++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y] + numbers[z] + numbers[a] + numbers[b];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 14)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- for (int z = y + 1; z < n; z++)
- {
- for (int a = z + 1; a < n; a++)
- {
- for (int b = a + 1; b < n; b++)
- {
- for (int c = b + 1; c < n; c++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y] + numbers[z] + numbers[a] + numbers[b] + numbers[c];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 15)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- for (int z = y + 1; z < n; z++)
- {
- for (int a = z + 1; a < n; a++)
- {
- for (int b = a + 1; b < n; b++)
- {
- for (int c = b + 1; c < n; c++)
- {
- for (int d = c + 1; d < n; d++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y] + numbers[z] + numbers[a] + numbers[b] + numbers[c] + numbers[d];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- if (n >= 16)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- for (int k = j + 1; k < n; k++)
- {
- for (int l = k + 1; l < n; l++)
- {
- for (int m = l + 1; m < n; m++)
- {
- for (int p = m + 1; p < n; p++)
- {
- for (int q = p + 1; q < n; q++)
- {
- for (int r = q + 1; r < n; r++)
- {
- for (int x = r + 1; x < n; x++)
- {
- for (int y = r + 1; y < n; y++)
- {
- for (int z = y + 1; z < n; z++)
- {
- for (int a = z + 1; a < n; a++)
- {
- for (int b = a + 1; b < n; b++)
- {
- for (int c = b + 1; c < n; c++)
- {
- for (int d = c + 1; d < n; d++)
- {
- for (int e = 0; e < n; e++)
- {
- sum = numbers[i] + numbers[j] + numbers[k] + numbers[l] + numbers[m] + numbers[p] + numbers[q] + numbers[r] + numbers[x] + numbers[y] + numbers[z] + numbers[a] + numbers[b] + numbers[c] + numbers[d] + numbers[e];
- if (sum == s)
- {
- subsetsCount++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- else
- {
- Console.WriteLine(subsetsCount);
- return;
- }
- Console.WriteLine(subsetsCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement