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

Блог пользователя 013

Автор 013, история, 8 лет назад, По-английски

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?

  • Проголосовать: нравится
  • +15
  • Проголосовать: не нравится