题目链接 给一个字符串, 由( ) 以及? 组成, 将?换成( 或者 ) 组成合法的括号序列, 每一个?换成( 或者 ) 的代价都不相同, 问你最小代价是多少, 如果不能满足输出-1. 弄一个变量num, 如果是( 那么num++,如果是)那么num--. 如果碰到?, 那么先将这个地方弄成), 然后把make_pair(b-a, i)加到一个队列里面.a是换成左括号的值, b是换成右括号的值, i是这个位置的坐标. 如果遇到num小于0的情况, 那么就将队首元素取出, 将这个位置换成左括号.…
Least Cost Bracket Sequence CodeForces - 3D 题目描述 This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example,…
D. Least Cost Bracket Sequence 题目连接: http://www.codeforces.com/contest/3/problem/D Description This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a…
Least Cost Bracket Sequence(贪心) Describe This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequenc…
This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and…
题目 This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()"…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequ…
Codeforces 3 D 题意:有一个括号序列,其中一些位置是问号,把第\(i\)个问号改成(需要\(a_i\)的代价,把它改成)需要\(b_i\)的代价. 问使得这个括号序列成立所需要的最小代价. 思路1: 这个是正统的贪心. 首先我们假设所有的位置上都是),那么我们在从左向右扫描的途中会发现一些问题. 比如:我们原来的序列是(??),现在假设成了())),那么在第三个字符处就会发现我们的打开的左括号数量为\(-1\),这是肯定不行的,所以我们必须把第二个字符或者第三个字符改成左括号以把左…
Description 给出一个括号序列,中间有一些问号,将第i个问号换成左括号代价是a[i],换成右括号代价是b[i],问如果用最少的代价将这个括号序列变成一个合法的括号序列 Input 第一行一个括号序列,假设其中有m个问号,则之后输入m行,每行两个整数a[i]和b[i]表示把第i个问号换成左括号或右括号的代价(括号序列长度不超过5e4,1<=a[i],b[i]<=1e6) Output 如果不存在一种合理的替换方案使得该序列变成一个合法的括号序列则输出-1,否则输出最小代价和替换后的合法…
传送门 Description 给一个序列,序列里面会有左括号.问号.右括号.对于一个\(?\)而言,可以将其替换为一个\((\),也可以替换成一个\()\),但是都有相应的代价.问:如何替换使得代价最小.前提是替换之后的序列中,括号是匹配的.如果不能替换为一个括号匹配的序列则输出-1. Input 第一行是序列,序列长度不超过\(5~\times10^4\),下面m(m是\(m\)的数量)行有每行\(2\)个数据,第一个是\((\)的代价,第2个是\()\)的代价 Output 第一行输出最小…