Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Parenthesize An Expression To Produce A Certain Value

Правка en1, от 013, 2016-04-27 07:37:16

Given an expression E and another integer 'k' , you are required to find out whether it is possible to parenthesize E such that it evaluates to 'k'. If the answer is YES, print the corresponding parenthesized expression. Assume the max and min value of E will be within -N and +N where N ≤ 10000 and the value of  - N ≤ k ≤ N.

Sample Input and output:

Input: E = 2 + 3 * ( - 1) + 4 + ( - 7), k = 8

Output: Yes. E = (2 + 3) * (( - 1) + 4) + ( - 7) = 8

Can this problem be solved in O(n2N)? If yes then how? If no then what is the best complexity to solve it?

Теги parenthesis, dp

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский 013 2016-04-27 07:37:16 607 Initial revision (published)