Advertisement blocking software were detected ;( Please add this webpage to whitelist.

LISA - Pocket Money

no tags 

Young people spend a lot of money on things like sweets, music CDs, mobile phones and so on. But most young girls/boys have one problem: Their pocket money is not enough for all these jolly things. Little Lisa Listig is one of these poor girls with a small pocket money budget. Last month her pocket money lasted only one week. So she decided to enter into negotiations with her father. Her father Tomm - a mathematician - had an incredibly ingenious idea: He wrote down some fancy digits with operators (+,*) in between them on a sheet of paper and allowed Lisa to insert brackets. Then he declared that the result of that arithmetic expression is Lisa's new pocket money. Now it's Lisa's task to maximize her pocket money. As her father was surprised what a huge sum of money Lisa got for her result, he decided to minimize the result of the expression for his son Manfred. Now it's your task to calculate the results obtained by Lisa and her father.


The first line of input contains the number of testcases k ( k< 5000 ). Each of the following k lines consists of an arithemtic expression. This expression consists of numbers (0-9) seperated by one of the two operators '*' and '+'. There are no spaces between the characters. Each line contains less than 100 characters.


For each expression output the result obtained by Lisa and the result obtained by her father separated by one space. The results of the calculations are smaller than 264.



105 27

Two possible expressions for the first testcase:

105 = (1+2)*(3+4)*5
27  = 1+2*3+4*5


hide comments
hashem sllat: 2015-10-20 21:28:02

Last edit: 2015-10-20 21:28:52
Shashank Tiwari: 2015-09-16 19:04:57

solved it with dp in o(n^3) solution

!!AV!!: 2015-06-03 23:14:33

classical DP problem

i_am_looser: 2015-05-22 15:10:34

Answer for 2*0*3+7+1*0*3
42 0
don't be confuse..... : )

Aadil Ahmad: 2015-04-09 04:55:31

Classic :)

shuks: 2015-01-20 18:19:36

Nice variation of Matrix Chain Multiplication ;)

Anmol Pandey: 2015-01-19 18:57:36

Nice Classical DP <3

Rajat (1307086): 2014-10-10 02:49:13

!!!!!!!SPOILER ALERT!!!!!!!
Learnt a matrix multiplication application of DP and got AC in one go...

Apoorv Gupta: 2014-06-14 17:54:52

What should be the answer for ->

It should be
42 0
2*((0*3+7+1*0)*3) = 42

However, solutions with answer 14 are getting ac, and the one with 42 are getting WA. Why so ?

Amey Telawane: 2014-02-01 09:45:09

why time limit=32 seconds.? mine was done in 0.21 without using fast io..

Added by:Simon Gog
Time limit:32s
Source limit:8082B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: ERL JS
Resource:Ulm Algorithm Course SoSe 2005