Problem Introduction

In the problem, your goal is to add parentheses to a given arithmetic expression to maximize its value.

Problem Description

Task.Find the maximum value of an arithmetic expression by specifying the order of applying its arithmetic operations using additional parentheses.

Input Format.The only line of the input contains a string \(s\) of length \(2n+1\) from some \(n\), with symbols \(s_0, s_1, \cdots, s_{2n}\). Each symbol at an even position of \(s\) is a digit(that is, an integer from 0 to 9) while each symbol at an odd position is one of three operations from \(\{+,-,*\}\).

Constraints.\(1 \leq n \leq 14\)(hence the string contains at most 29 symbols).

Output Format.Output the maximum possible value of the given arithmetic expression among different orders of applying arithmetic operations.

Sample 1.
Input:

1+5

Output:

6

Sample 2
Input:

5-8+7*4-8+9

Output:

200

Solution

[UCSD白板题] Maximize the Value of an Arithmetic Expression的更多相关文章

  1. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  2. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  3. [UCSD白板题] Take as Much Gold as Possible

    Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...

  4. [UCSD白板题] Primitive Calculator

    Problem Introduction You are given a primitive calculator that can perform the following three opera ...

  5. [UCSD白板题] Points and Segments

    Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...

  6. [UCSD白板题] Number of Inversions

    Problem Introduction An inversion of a sequence \(a_0,a_1,\cdots,a_{n-1}\) is a pair of indices \(0 ...

  7. [UCSD白板题] Sorting: 3-Way Partition

    Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...

  8. [UCSD白板题] Majority Element

    Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...

  9. [UCSD白板题] Binary Search

    Problem Introduction In this problem, you will implemented the binary search algorithm that allows s ...

随机推荐

  1. PPTP-VPN第三章——用户流量与并发数限制

    在前面两篇文章中详细介绍了pptp vpn的安装与使用,以及如何配置用户认证存入mysql数据库.本文将在前面两篇文章的基础上介绍如何对用户的流量做限制,同时限制相同账号的用户,同一时刻的在线数为1. ...

  2. 解决:NoSuchAlgorithmException: Algorithm HmacSHA1 not available

    windows下运行macInstance = Mac.getInstance("HmacSHA1");完全正常,Linux下则出现异常: java.security.NoSuch ...

  3. HTML5 ---localStorage

    HTML5中提供了localStorage对象可以将数据长期保存在客户端,直到人为清除. localStorage提供了几个方法: 1.存储:localStorage.setItem(key,valu ...

  4. HTTP、TCP、UDP以及SOCKET之间的区别/联系

    一.TCP/IP代表传输控制协议/网际协议,指的是一系列协组. 可分为四个层次:数据链路层.网络层.传输层和应用层. 在网络层:有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议. 在 ...

  5. Convert.ToInt32,int.Parse,int.TryParse,(int)的区别

    1 (int)变量名[强制类型转换] 该转换方式主要用于数字类型转换,从int类型到long,float,double,decimal类型,可以使用隐式转换,但是从long类型到int类型就需要使用显 ...

  6. 使用mysql 命令行,增加 ,删除 字段 并 设置默认值 及 非空

    使用mysql 命令行,增加 ,删除 字段 并 设置默认值 及 非空 添加 alter table table_name add field_name field_type; 添加,并设置默认值,及非 ...

  7. sublime插件 cssComb实现css自动排序及格式化

    cssComb是一个实现css代码自动排序,当然顺便也实现了代码的格式化 安装: 首先需要打开sublime搜索安装csscomb插件(前提是已经安装了sublime的package control) ...

  8. 2-2. Initializing Objects with Initializer Lists

    Using Uniform Initialization to Construct a vector #include <iostream> #include <vector> ...

  9. DIV+CSS常用的网页布局代码

    单行一列以下是引用片段:body { margin: 0px; padding: 0px; text-align: center; }#content { margin-left:auto; marg ...

  10. zookeeper学习(一)安装、配置、运行

    说明:zookeeper完全可以standalone,也可以伪集群形式,当然生产中都是集群形式.另外,也可以在windows下运行. 如果只是研究用,完全可以在windows下使用standalone ...