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

【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)的更多相关文章

  1. BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟

    Description Recently, the cows have been competing with strings of balanced  parentheses and compari ...

  2. B3300 [USACO2011 Feb]Best Parenthesis 模拟

    这是我今天遇到最奇怪的问题,希望有人帮我解释一下... 一开始我能得90分: #include<iostream> #include<cstdio> #include<c ...

  3. BZOJ3300: [USACO2011 Feb]Best Parenthesis

    3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 42 ...

  4. [BZOJ] 3301: [USACO2011 Feb] Cow Line

    康拓展开/逆展开 模板 #include<algorithm> #include<iostream> #include<cstdio> #define int lo ...

  5. BZOJ 2274 [Usaco2011 Feb]Generic Cow Protests

    [题解] 很容易可以写出朴素DP方程f[i]=sigma f[j] (sum[i]>=sum[j],1<=j<=i).  于是我们用权值树状数组优化即可. #include<c ...

  6. [USACO2011 Feb]Best Parenthesis

    Time Limit: 10 Sec Memory Limit: 128 MB Description Recently, the cows have been competing with stri ...

  7. 【BZOJ】【3301】【USACO2011 Feb】Cow Line

    康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...

  8. 3301: [USACO2011 Feb] Cow Line

    3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit ...

  9. BZOJ2274: [Usaco2011 Feb]Generic Cow Protests

    2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 196  Solve ...

随机推荐

  1. python版本管理--pyenv

    python版本环境管理 下载依赖 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readli ...

  2. 五中不同的思路输出helloword

    五中不同的思路输出helloword -- 我也不知道了--

  3. Shell 传递参数(转)

    我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 实例 以下实例我们向脚本传递三 ...

  4. Android双向seekbar

    ※效果 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/disso ...

  5. Ubuntu 下apache2 增加新的module

    http://andrew913.iteye.com/blog/398648 首先来介绍下apache的一个工具apxs.apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译 ...

  6. Linux 文件系统类型 文件系统结构 与Windows文件系统的比较

    摘自:http://blog.csdn.net/gelivable007/article/details/7249365 Linux 文件系统类型 磁盘文件系统.包括硬盘.CD-ROM.DVD.USB ...

  7. 转发:【PHP】转义和过滤html单、双引号及HTML标签

    一.单引号和双引号转义在PHP的数据存储过程中用得比较多,即往数据库里面存储数据时候需要注意转义单.双引号: 先说几个PHP函数: 1.addslashes — 使用反斜线引用(转义)字符串: 返回字 ...

  8. 将table中的值转换成json格式传到后台接收处理。

    table数据 <table style="border:1px" id="tableID"> <tr> <th>编号< ...

  9. MQTT 学习笔记

    MQTT特点 MQTT协议是为大量计算能力有限,且工作在低带宽.不可靠的网络的远程传感器和控制设备通讯而设计的协议. 1.使用发布/订阅消息模式,提供一对多的消息发布,解除应用程序耦合 2.对负载内容 ...

  10. pythselenium webdriver

    转自:http://www.cnblogs.com/fnng/archive/2013/06/16/3138283.html 原文档地址: http://docs.seleniumhq.org/doc ...