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 ...
随机推荐
- promise VS future
Future and Promise are the two separate sides of an asynchronous operation. promise is used by the & ...
- 共享访问在.NET中的编程实现
转载:http://blog.csdn.net/zhzuo/article/details/1732937 共享访问在.NET中的编程实现 发布日期:2007-08-08 | 更新日期:2009-03 ...
- mysql 数据表操作 存储引擎介绍
一 什么是存储引擎? 存储引擎就是表的类型. mysql中建立的库===>文件夹 库中建立的表===>文件 现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制 ...
- this与$scope
最近在Angular项目中遇到关于controller内使用$scope&this 暴露数据的问题,下面来分析一下: "controller as" 是Angular在1. ...
- [LeetCode] 711. Number of Distinct Islands II_hard tag: DFS
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- Linux CentOS6.5下编译安装MySQL 5.6
检查:卸载掉原有MySql 因为mysql数据库在Linux上实在是太流行了,所以目前下载的主流Linux系统版本基本上都集成了mysql数据库在里面,我们可以通过如下命令来查看我们的操作系统上是否已 ...
- windows上备份mysql数据库
方案一:采用mysql自带的工具mysqldump. 脚本文件backup.bat如下: set "YMD=%date:~,4%%date:~5,2%%date:~8,2%"cd ...
- c#: using Microsoft.Office.Interop.Excel 异常
解决方法: Project>Reference>右键Add Reference...>Choose Microsoft Excel 15.0 Object Library
- centos 网卡配置
地址:/etc/sysconfig/network-scripts vi /etc/sysconfig/network-scripts/ifcfg-eth0 1.固定ip配置 DEVICE=eth0 ...
- PHP多进程并行执行php脚本
<?php //fork.php $cmds = [ '/data/wwwroot/default/test1.php', '/data/wwwroot/default/test2.php', ...