http://www.lydsy.com/JudgeOnline/problem.php?id=3300

这个细节太多QAQ

只要将所有的括号'('匹配到下一个')'然后dfs即可

简单吧,,,

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%lld", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i] << ' '; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=100005;
const long long MD=12345678910;
int n, q[N], top, inext[N];
long long dfs(int l, int r) {
int rr=inext[l];
long long ret=0;
if(l!=rr-1) ret=(ret+((dfs(l+1, rr-1)<<1)%MD))%MD;
else if(l==rr-1) ret=(ret+1)%MD;
if(rr+1<=r) ret=(ret+(dfs(rr+1, r)%MD))%MD;
return ret;
} int main() {
read(n);
for1(i, 1, n) {
int t=getint();
if(!t) q[++top]=i;
else inext[q[top--]]=i;
}
print(dfs(1, n));
return 0;
}

Description

Recently, the cows have been competing with strings of balanced
parentheses and comparing them with each other to see who has the
best one.

Such strings are scored as follows (all strings are balanced): the
string "()" has score 1; if "A" has score s(A) then "(A)" has score
2*s(A); and if "A" and "B" have scores s(A) and s(B), respectively,
then "AB" has score s(A)+s(B). For example, s("(())()") =
s("(())")+s("()") = 2*s("()")+1 = 2*1+1 = 3.

Bessie wants to beat all of her fellow cows, so she needs to calculate
the score of some strings. Given a string of balanced parentheses
of length N (2 <= N <= 100,000), help Bessie compute its score.

计算“平衡字符串”的分数,“平衡字符串”是指由相同数量的‘(’和‘)’组成,
且以‘(’开头,以‘)’结尾的字符串。
计算规则:
字符串“()”的得分是1.
如果,平衡字符串“A”的得分是是S(A),那么字符串“(A)”得分是2*S(A) ;
如果,“A”,“B” 得分分别是S(A)和S(B),那么平衡字符串“AB”得分为S(A)+S(B)
例如:s("(())()") =s("(())")+s("()") = 2*s("()")+1 = 2*1+1 = 3.

Input

* Line 1: A single integer: N

* Lines 2..N + 1: Line i+1 will contain 1 integer: 0 if the ith
character of the string is '(', and 1 if the ith character of
the string is ')'
第1行:N,平衡字符串长度
第2至N+1行:Linei+1 整数0或1,0代表字符‘(’,1代表‘)’

Output

* Line 1: The score of the string. Since this number can get quite
large, output the score modulo 12345678910.
计算字符串得分,结果对12345678910取模

Sample Input

6
0
0
1
1
0
1
INPUT DETAILS:

This corresponds to the string "(())()".

Sample Output

3

HINT

Source

最新文章

  1. layer-list实现只有左、右和下边框的圆角矩形
  2. [ASP.NET] 使用 ASP.NET SignalR 添加实时 Web
  3. net start mysql服务名无效
  4. uoj #9. 【UTR #1】vfk的数据 水题
  5. spring+hibernate+jpa+Druid的配置文件,spring整合Druid
  6. cas+tomcat+shiro实现单点登录-1-tomcat添加https协议
  7. sql server基础学习之引号
  8. 使用 POJO 对象绑定请求参数
  9. snowflake主键生成策略
  10. Java循环和条件
  11. 程序员之路:python3+PyQt5+pycharm桌面GUI开发
  12. 利用JAVA API函数实现数据的压缩与解压缩
  13. 有了这些,java IO就不愁了
  14. Vnpy二次开发应用所需图标
  15. 修复Mysql主从不同步shell
  16. 192 Word Frequency
  17. 第一次项目上Linux服务器(八:——搭建Nginx图片服务器)
  18. USBDM Debugger interface for Freescale RS08,HCS08,HCS12,Coldfire and ARM-Kinetis Devices.
  19. &lt;Android 基础(二十五)&gt; Frame Animation
  20. 【Android架构综述篇】之应用程序、应用程序訪问硬件的流程

热门文章

  1. Mybatis错误:Result Maps collection already contains value for 。。。。
  2. Zxing二维码扫描
  3. PageRank学习
  4. js 常用类型转换简写
  5. 7.12归来赛_B
  6. ThreadLocal源码
  7. C#指南,重温基础,展望远方!(1)C#语言介绍
  8. 使用结构(C# 编程指南)
  9. Lintcode---单词的添加与查找
  10. maven介绍 极客学院