Skip to content

computing max value by putting parenthese around operands and operators

Notifications You must be signed in to change notification settings

wangjingyi/maxvalue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Problem: You are given an arithmetic expression containing N real numbers and N - 1 operators, each either + or *. Your goal is to perform the operations in an order that maximizes the value of the expression. That is, insert N - 1 pairs of parentheses into the expression so that its value is maximized.

For example,

1).  For the expression 6 * 3 + 2 * 5, the optimal ordering is to add the middle numbers first, then perform the multiplications: ((6 * (3 + 2))  * 5) = 150. 

2).  For the expression 0.1 * 0.1 + 0.1, the optimal ordering is to perform the multiplication first, then the addition: ((0.1 * 0.1) + 0.1) = 0.11. 

3).  For the expression (-3) * 3 + 3, the optimal ordering is ((-3) * 3) + 3) = -6.

About

computing max value by putting parenthese around operands and operators

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages