Atcoder ABC 169 F

Правка en1, от LIFE_GOES_ON, 2020-07-18 10:00:40

My observation is : Let an array A has length n and a subset of A is B. Now, if B has length k then it appears also in other 2^(n-k) subsets of array A.

So I used a 2d dp dp[i][j] which denotes if I take elements upto i then how many subsets have remaining sum j. And the ans is dp[n][0].

Base case is when i >= n then if the remaining sum is 0 that means we got a subset having sum S. Now we have to return in how many other subsets the current segment belongs. So if remaining sum = 0 then I returned pow(2,n-k) otherwise 0;

I thought this is the correct approach. Please correct my approach. I don't understand why it is not working.

Problem Link

My Code

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский LIFE_GOES_ON 2020-07-18 10:00:40 2011 Initial revision (published)