247. Ways to Make an Expression
HardInterval DP
Given numbers separated by + − *, count the different results of all ways to fully parenthesise the expression and print the number of distinct values obtained.
Input format
A single expression without spaces (non-negative integers and + − *).
Output format
The number of distinct results.
Example 1
Input
2-1-1
Output
2
Example 2
Input
2*3-4*5
Output
4
Constraints
Up to 10 numbers.
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…