Count Number Of Subsequences

3.3

3 votes
Algorithms, Combinatorics, Permutation Cycles, Permutation and combination, Math
Problem

Consider a sequence A of N integers, where the absolute value of each element is limited to 1. For every value x in the range N to N, find the count of non-empty subsequences of A whose sum of elements equals x. The answer should be printed modulo 109+7.

Input format:

First line contains N, the number of elements in the array

Next line contain N spaced integers the elements of the array A

Output format:

Print 2N spaced integers denoting the count of non-empty subsequences of A  for every value x in the range N to N 

Constraints: 

1<=N<=105|Ai|<=1

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Subsequences with sum 0 :- {0}

Subsequences with sum 1:- {1},{1,0}

Editor Image

?