大意: n个括号, 位置未知, 给出每对括号左右间距, 求输出一个合法括号序列. 最后一个括号间距一定为1, 从右往左遍历, 每次括号划分越小越好. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #include <s…
大意: 给定序列$a$, 某些位置为'?', 求给'?'赋值使得序列$(a_1+a_2+...+a_k,a_2+a_3+...+a_{k+1},...)严格递增, 且$\sum|a_i|$最小. 化简一下可以得到$a_1<a_{k+1}<a_{2k+1}<...,a_2<a_{k+2}<a_{2k+2}<...$, 所以每一部分都是独立的, 所以单独考虑k个部分, 贪心使得$\sum|a_i|$最小即可. #include <iostream> #inclu…
http://blog.csdn.net/libin56842/article/details/9673239 http://www.cnblogs.com/ACMan/archive/2012/08/09/2630497.html http://blog.csdn.net/chaiyuan414/article/details/5448699 #include <iostream> #include <string> #include <cstring> #inclu…
题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input standard input output standard output Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. A…
E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input standard input output standard output Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthu…
Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int>…
E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input standard input output standard output Notice that the memory limit is non-standard. Recently Arthur and Sasha have studied correct bracket sequences. Arthu…
冲鸭,去刷题:http://codeforces.com/contest/1153/problem/C C. Serval and Parenthesis Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Serval soon said goodbye to Japari kindergarten, and b…
Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and if a and b are regul…
题目链接:http://codeforces.com/problemset/problem/5/C 题目大意:给出一串字符串只有'('和')',求出符合括号匹配规则的最大字串长度及该长度的字串出现的次数.解题思路:设dp[i]为到i的最大括号匹配,我们每次遇到一个'('就将其下标存入栈中,每次遇到')'就取出当前栈中里它最近的'('下标即栈顶t.不能直接dp[i]=i-t+1,比如(()()())这样的例子就会出错,应为dp[i]=dp[i-1]+i-t+1. 代码 #include<bits/…