Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TinhTong
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] a = nhapDuLieu();
- task(a);
- }
- static void task(int[] a)
- {
- int s = 0;
- for (int i = 0; i < a.Length; i++)
- {
- s += a[i];
- }
- bool[,] res = new bool[2, s + 1];
- res[0, s] = true;
- res[0, a[0]] = true;
- for (int i = 1; i < a.Length; i++)
- {
- for (int j = 0; j < res.GetLength(1) - 1; j++)
- {
- if (res[0, j] == true) res[1,j + a[i]] = true;
- }
- res[0, a[i]] = true;
- for (int j = 0; j < res.GetLength(1); j++)
- {
- if (res[1, j] == true) res[0, j] = true;
- }
- }
- int total = 0;
- for (int i = 0; i < res.GetLength(1); i++)
- {
- if (res[0, i] == true) total++;
- }
- Console.WriteLine(total);
- for (int i = 0; i < res.GetLength(1); i++)
- {
- if (res[0, i] == true) Console.Write(i + " ");
- }
- Console.WriteLine();
- }
- static int[] nhapDuLieu()
- {
- int n = int.Parse(Console.ReadLine());
- int[] input = new int[n];
- string temp = Console.ReadLine();
- string[] splitData = temp.Split(' ');
- for (int i = 0; i < splitData.Length; i++)
- {
- input[i] = int.Parse(splitData[i]);
- }
- return input;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement