【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)
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
0
0
1
1
0
1
INPUT DETAILS:
This corresponds to the string "(())()".
Sample Output
HINT
Source
【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)的更多相关文章
- BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟
Description Recently, the cows have been competing with strings of balanced parentheses and compari ...
- B3300 [USACO2011 Feb]Best Parenthesis 模拟
这是我今天遇到最奇怪的问题,希望有人帮我解释一下... 一开始我能得90分: #include<iostream> #include<cstdio> #include<c ...
- BZOJ3300: [USACO2011 Feb]Best Parenthesis
3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 89 Solved: 42 ...
- [BZOJ] 3301: [USACO2011 Feb] Cow Line
康拓展开/逆展开 模板 #include<algorithm> #include<iostream> #include<cstdio> #define int lo ...
- BZOJ 2274 [Usaco2011 Feb]Generic Cow Protests
[题解] 很容易可以写出朴素DP方程f[i]=sigma f[j] (sum[i]>=sum[j],1<=j<=i). 于是我们用权值树状数组优化即可. #include<c ...
- [USACO2011 Feb]Best Parenthesis
Time Limit: 10 Sec Memory Limit: 128 MB Description Recently, the cows have been competing with stri ...
- 【BZOJ】【3301】【USACO2011 Feb】Cow Line
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...
- 3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 82 Solved: 49[Submit ...
- BZOJ2274: [Usaco2011 Feb]Generic Cow Protests
2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 196 Solve ...
随机推荐
- iOS key value coding kvc在接收json数据与 model封装中的使用
iOS key value coding kvc在接收json数据与 model封装中的使用 使用 kvc 能够极大的简化代码工作,及以后的接口维护工作: 1:先创建MovieModel类.h和 . ...
- Activity生命周期以及启动模式对生命周期的影响(二)
前面一篇文章概述了Android四大组件之一的Activity生命周期方法的调用先后顺序,但对于非标准启动模式下Activity被多次调用时的一些生命周期方法并未详细阐述,现在针对该情况着重记录. 现 ...
- [Unity3D]场景间切换与数据传递(以及物体删除技巧)
http://blog.163.com/kingmax_res/blog/static/77282442201031712216508/ 先介绍一些基本函数(具体用法自己查文档):---------- ...
- swagger 生成的接口文档,隐藏接口的某个参数
[问题描述] controller 中的处理请求的方法,有时候会添加一些额外的参数.比如下面代码中 UserVo: @PostMapping(value = "/add-office-par ...
- hibernate查询排序
hibernate提供了两种排序方式:1:数据库排序,也就是说通过SQL语句在数据库内部就进行完了排序.2.内存排序,也就是说在数据库中把数据加载到内存中后在进行排序.推荐使用第一种排序方式,因为在数 ...
- Popup.js
test.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> ...
- Linux 网卡丢包严重
http://hi.baidu.com/scstwy/item/cad0fbef1fdc18d3eb34c9d9
- MapReduce实现两表的Join--原理及python和java代码实现
用Hive一句话搞定的,可是有时必需要用mapreduce 方法介绍 1. 概述 在传统数据库(如:MYSQL)中,JOIN操作是很常见且很耗时的.而在HADOOP中进行JOIN操作.相同常见且耗时, ...
- Top 10 Project Management Software
- @@identity、scope_identity()、IDENT_CURRENT('tablename')函数的区别
@@IDENTITY 和SCOPE_IDENTITY 返回在当前会话中的任何表内所生成的最后一个标识值.但是,SCOPE_IDENTITY 只返回插入到当前作用域中的值:@@IDENTITY 不受限于 ...