BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟
Description
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
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 模拟的更多相关文章
- BZOJ3300: [USACO2011 Feb]Best Parenthesis
3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 89 Solved: 42 ...
- B3300 [USACO2011 Feb]Best Parenthesis 模拟
这是我今天遇到最奇怪的问题,希望有人帮我解释一下... 一开始我能得90分: #include<iostream> #include<cstdio> #include<c ...
- 【BZOJ】3300: [USACO2011 Feb]Best Parenthesis(模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #i ...
- [USACO2011 Feb]Best Parenthesis
Time Limit: 10 Sec Memory Limit: 128 MB Description Recently, the cows have been competing with stri ...
- 3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 82 Solved: 49[Submit ...
- 【BZOJ】【3301】【USACO2011 Feb】Cow Line
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:( ...
- BZOJ2274: [Usaco2011 Feb]Generic Cow Protests
2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 196 Solve ...
- BZOJ3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 67 Solved: 39[Submit ...
- 2272: [Usaco2011 Feb]Cowlphabet 奶牛文字
2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 138 Solved: 97 ...
随机推荐
- flask-WTForms组件
WTForms是一个支持多个web框架的form组件 主要能够帮助我们生成html标签 对数据进行验证 安装 pip install wtforms Wtforms的使用 这里借助一个用户登录注册的示 ...
- 几种常用CSS3样式
在我们日常工作中,由于考虑到浏览器的兼容性,所以很少用CSS3样式.关于其标准,W3C 仍然在对 CSS3 规范进行开发.不过,现代浏览器已经实现了相当多的 CSS3 属性.最近学习了CSS3,发现功 ...
- IO流(8)递归删除带文件的目录
递归删除带内容的目录 * * 目录给定:demo * * 分析: * A:封装目录 * B:获取该目录下的所有文件或者文件夹的File数组 * C:遍历该File数组,得到每一个File对象 * D: ...
- Lodash 中文文档 (v4.16.1) 手机版
http://lodash.swift.ren/ 手机扫描二维码直接进入
- 【剑指offer】 二叉树中和为某一值的路径
一.题目: 输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长度 ...
- Hadoop 之日志管理—应用在 YARN 中运行时的日志
背景: 在写这篇博文前,自己一直没有弄明白一个问题,“在 Map 函数和 Reduce 函数中使用 System.out.print 打印日志时,输出内容在哪里显示?”.试了好多回,在 log/* 目 ...
- Linux中Readlink命令
原文地址:http://blog.csdn.net/liangxiaozhang/article/details/7356829 readlink是Linux系统中一个常用工具,主要用来找出符号链接所 ...
- 搭建私有yum仓库
需要工具: centos7 nginx rsync 新建文件夹存放镜像数据 mkdir /data mkdir /data/yum_data 同步数据 国内开源镜像站没有几个支持rsync,科技大学的 ...
- Oracle彻底删除11gR2 GI
Oracle彻底删除11gR2 GI 环境:RHEL 6.5 + Oracle 11.2.0.4 GI 需求:在搭建Standby RAC时,安装GI软件期间由于GI安装遇到一些问题,root脚本执行 ...
- c# 日期函数[string.Format----GetDateTimeFormats]格式
DateTime dt = DateTime.Now;Label1.Text = dt.ToString();//2005-11-5 13:21:25Label2.Text = dt.ToFileTi ...