[UCSD白板题] Maximize the Value of an Arithmetic Expression
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的更多相关文章
- [UCSD白板题] Longest Common Subsequence of Three Sequences
Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...
- [UCSD白板题] Compute the Edit Distance Between Two Strings
Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...
- [UCSD白板题] Take as Much Gold as Possible
Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...
- [UCSD白板题] Primitive Calculator
Problem Introduction You are given a primitive calculator that can perform the following three opera ...
- [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 ...
- [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 ...
- [UCSD白板题] Sorting: 3-Way Partition
Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...
- [UCSD白板题] Majority Element
Problem Introduction An element of a sequence of length \(n\) is called a majority element if it app ...
- [UCSD白板题] Binary Search
Problem Introduction In this problem, you will implemented the binary search algorithm that allows s ...
随机推荐
- PPTP-VPN第三章——用户流量与并发数限制
在前面两篇文章中详细介绍了pptp vpn的安装与使用,以及如何配置用户认证存入mysql数据库.本文将在前面两篇文章的基础上介绍如何对用户的流量做限制,同时限制相同账号的用户,同一时刻的在线数为1. ...
- 初学c# -- 学习笔记(四)
想想,数据库先用mysql了,这玩意小且安装方便.前面web学了些,现在学winform的.数据库先看看便捷的mysql. 下载了一个mysql5.7版的,装上居然找不到密码,重装3.4回,找不到,说 ...
- Libevent 的多线程操作
起因是event_base 跨线程add/remove event 导致崩溃或者死循环. 据查:libvent 1.4.x是非线程安全的,要跨线程执行event_add,会有问题.因此传统做法是通过p ...
- SeekBar 圆角问题
用图片做背景色,最后处理成.9.png的.用普通png图片做背景,则两边会有圆角出现,原因是图片不适合SeekBar尺寸,因而被拉伸或压缩,从而产生圆角. <?xml version=" ...
- linux命令(6):rmdir 命令
rmdir命令 rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删除某目录时也必须具有对父目录的写 ...
- sdk添加新的C文件编译出错
make: *** 没有规则可以创建"test.elf"需要的目标"mike.c.o". 停止. 解决方法: 重新建立工程并且编译文件
- Linux如何复制,打包,压缩文件
(1)复制文件 cp -r 要copy的文件/("/"指的是包括里面的内容) newfile_name(要命名的文件名) eg:cp -r webapps_zero/ f ...
- VBA Excel 对比两列数据
Sub Md() ' ' Macro1 Macro ' 宏由 BX 录制,时间: 2012-6-8 ' 宏中的列数可以输入 A - IV 也可以输入 1-256 ' Dim i%, j%, i1%, ...
- mina IoBuffer
mina IoBuffer 常用方法 Limit(int) 如果position>limit, position = limit,如果mark>limit, 重置mark Mark() ...
- MVC5+EF6 Code First 从零开始——第一章
一直在用Database First 突然感觉关系复杂的时候,生成json经常出现死循环,不够灵活. 今天正好是周五,不太忙就想试试code first吧,试了2次,终于有结果. ok废话不多说,先撸 ...