Sum of products of all combination taken ( 1 to n ) at a time | Find the postfix sum array ; Modify the array such that we don 't have to compute the products which are obtained before ; Finding sum of all combination taken 1 to N at a time ; sum taken 1 at time is simply sum of 1 - N ; for sum of products for all combination ; finding postfix array ; sum of products taken i + 1 at a time ; modify the array for overlapping problem ; Driver 's Code ; storing numbers from 1 to N ; calling allCombination
def postfix ( a , n ) : NEW_LINE INDENT for i in range ( n - 1 , 1 , - 1 ) : NEW_LINE INDENT a [ i - 1 ] = a [ i - 1 ] + a [ i ] NEW_LINE DEDENT DEDENT def modify ( a , n ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT a [ i - 1 ] = i * a [ i ] ; NEW_LINE DEDENT DEDENT def allCombination ( a , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum += i NEW_LINE DEDENT print ( " f ( 1 ) ▁ - - > ▁ " , sum ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT postfix ( a , n - i + 1 ) NEW_LINE sum = 0 NEW_LINE for j in range ( 1 , n - i + 1 ) : NEW_LINE INDENT sum += ( j * a [ j ] ) NEW_LINE DEDENT print ( " f ( " , i + 1 , " ) ▁ - - > ▁ " , sum ) NEW_LINE modify ( a , n ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE a = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ i ] = i + 1 NEW_LINE DEDENT allCombination ( a , n ) NEW_LINE DEDENT