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

Solution

挺简单的,就是不会写而已(雾

细节很多

预处理出每个左括号对应的右括号(这个用栈就可以处理了)

然后$dfs$一遍求出答案,分类讨论一下就行

#include <bits/stdc++.h>

using namespace std ;

const int N = 1e5 +  ;
#define mod 12345678910
#define ll long long int n ;
int a[ N ] , top , st[ N ] ; ll dfs( int l , int r ) {
int qr = a[ l ] ;
ll ans = ;
if( l != qr - ) ans = ( ans + ( dfs( l + , qr - ) * ) % mod ) % mod ;
else if( l == qr - ) ans = ( ans + ) % mod ;
if( qr + <= r ) ans = ( ans + ( dfs( qr + , r ) % mod ) ) % mod ;
return ans ;
} int main() {
scanf( "%d" , &n ) ;
for( int i = ; i <= n ; i ++ ) {
int x ;
scanf( "%d" , &x ) ;
if( !x ) st[ ++ top ] = i ;
else a[ st[ top -- ] ] = i ;
}
printf( "%lld\n" , dfs( , n ) ) ;
return ;
}

BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟的更多相关文章

  1. BZOJ3300: [USACO2011 Feb]Best Parenthesis

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

  2. B3300 [USACO2011 Feb]Best Parenthesis 模拟

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

  3. 【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #i ...

  4. [USACO2011 Feb]Best Parenthesis

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

  5. 3301: [USACO2011 Feb] Cow Line

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

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

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

  7. BZOJ2274: [Usaco2011 Feb]Generic Cow Protests

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

  8. BZOJ3301: [USACO2011 Feb] Cow Line

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

  9. 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字

    2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 97 ...

随机推荐

  1. Html各组件MIME类型

    扩展名 类型/子类型 * application/octet-stream 323 text/h323 acx application/internet-property-stream ai appl ...

  2. csv参数化,数据驱动

    首先我们要有一个接口测试用例存放的地方,我们这里用EXCEL模板管理,里面包含用例编号.入参.优先级.请求方式.url等等. 1:新建一个txt文件,命名为sjqd,后缀名改为csv,右键excel格 ...

  3. Linux Packages Search

    网站 : https://www.pkgs.org/ https://centos.pkgs.org/

  4. vue学习之webpack

    本质上,Webpack是一个现代 JavaScript应用程序的静态模块打包器(module bundler).当 Webpack处理应用程序时,它会递归地构建一个依赖关系图(dependency g ...

  5. 多线程下载文件,ftp文件服务器

    1: 多线程下载文件 package com.li.multiplyThread; import org.apache.commons.lang3.exception.ExceptionUtils; ...

  6. iptables 常用命令

    iptables service iptables save \\保存 iptables -F \\清空所有规则 iptables -F -t nat \\清空nat表 iptables -t nat ...

  7. M2Eclipse:Maven Eclipse插件无法搜索远程库的解决方法

    使用Eclipse安装了maven插件之后,创建Maven工程,发现添加依赖“Add Dependency”的时候无法自动搜索远程库. 如果不能搜索远程库那用这个插件有啥用撒... 查遍了所有的mav ...

  8. Jmeter接口自动化测试 (四)(持续构建)

    本文转载至http://www.cnblogs.com/chengtch/p/6145867.html  Jmeter是压力测试.接口测试工具,Ant是基于Java的构建工具,具有跨平台的作用,jen ...

  9. http协议基础(七)通用首部字段

    通用首部字段的意思,就是:请求和响应报文双方都会使用的首部 1.Cache-Control 通过指定它的指令,能操作缓存的工作机制 指令参数是可选的,多个指令通过“,”分隔 Cache-Control ...

  10. cocos代码研究(6)有限时间动作类(FiniteTimeAction)学习笔记

    理论部分 有限时间动作类继承自Action类,被 ActionInstant(即时动作) , 以及 ActionInterval(持续动作) 继承. 即时动作是会立即被执行的动作,被 CallFunc ...