考虑在一个确定的括号序列中,我们可以枚举中间位置,按左右最长延伸出去的答案计算. 我们很自然的思考,我们直接维护左右两边,在删除一些字符后能够延伸的最长长度. 我们设\(f_{i,j}\)为\(i\)点合法删除向左延伸的最大长度. \( f_{i,j} = \left\{ \begin{aligned} &f_{i - 1,j} (a[i] = ')'\ )\\ &f_{i - 1,j - 1}(a[i] = ')'\ )\\ &f_{i - 1,j} + f_{i - 1 ,j…
考虑\(D1\)的\(O(n^2)\),我们直接进行组合处理. 考虑在\(p\)这个位置,左边有\(l\)个(,右边有\(r\)个),左边有\(l\)个问号,右边有\(r\)个问号. 这个位置的贡献为: \(\sum_{i = 0} ^ x (l+i)\binom{x}{i}\binom{y}{l + i - r}\) 考虑我们拆项. \(l\sum_{i = 0} ^ x\binom{x}{i}\binom{y}{l + i - r} + \sum_{i = 0} ^ x i\binom{x}…
http://codeforces.com/problemset/problem/1216/E1 E1. Numerical Sequence (easy version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between the easy and the hard ver…
我们枚举每两个字符的空档,统计一个空档左边有 \(l\) 个左括号, 右边有 \(r\) 个右括号,左边有 \(u\) 个问号,右边有 \(v\) 个问号. 则对于 \(p\) 的答案 \(ans_p\) 有: \[ans_p=\sum\limits_{i=0}^{u}(l+i)\dbinom{u}{i}\dbinom{v}{l+i-r} \] 解释: 对于每个左边的问号枚举有几个变成左括号,则左边有 \(l+i\) 个左括号,方案数为 \(C_{u}^{i}\) ,右边的问号显然有 \(l+i…
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序列中,必定存在一个满足前面只由一段左括号,后面只由一段右括号组成,因此我们考虑枚举这中间位置在原括号序列中对应哪个位置,那么假设这个断点位于 \(i\) 和 \(i+1\) 之间,我们设 \(i\) 及之前有 \(x\) 个左括号,\(i+1\) 及之后有 \(y\)​​ 个右括号,那么显然以这个位置为端点…
B. Ping-Pong (Easy Version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to in…
CF1225B1 TV Subscriptions (Easy Version) 洛谷评测传送门 题目描述 The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the kk TV shows. You know the schedule for the next nn days: a seque…
                                    Bracket Sequence Time Limit: 3000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status] Description There is a sequence of brackets, which supports two kinds of operations.1. we c…
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A bracket sequence is a string, containing only characters "(", ")"…
E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbrev…