algorithm - Finding product of all elements of all sub arrays of an array -


i having array having n elements. want find out multiplication of elements in sub arrays possible of array a. expecting solution implemented of dp. want store product values in array b. beginner programming. have done lot of google search unable find exact solution query. can me provide me logic of question. example:

a={1,2,3} 

all possible sub arrays

{{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}} 

so possible products

{1,2,3,2,3,6,6}  

respectively.

any appreciable. in advance.

this might help:

at every instance have make 2 choices:

either select element of array in current sub-array or don't.the following recursion might help:

f(i,p)=f(i+1,p*arr[i])||f(i+1,p)


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -