描述

You are given a sequence S of parentheses. You are asked to insert into S as few parentheses as possible so that the resulting sequence T is well matched.

It's not difficult. But can you tell how many different T you can get?

Assume S = ()), you can get either (()) or ()().

输入

One line contains the sequence S.

For 30% of the data, 1 ≤ |S| ≤ 10

For 60% of the data, 1 ≤ |S| ≤ 200

For 100% of the data, 1 ≤ |S| ≤ 1000

输出

Output 2 integers indicating the minimum number of parentheses need to be inserted into S and the number of different T. The number of different T may be very large, so output the answer modulo 109+7.

样例输入
())
样例输出
1 2

只考虑左边(比右边)多的情况,也就是消掉匹配的()之后的比如(((((()消掉匹配的后只有(((((的情况
现在考虑如下"("比")"多
((()()( => ((( 那么第一个(和第二个(之间最多只能有1个),至少0个
那么第二个(和第三个(之间最多只能有2个),至少0个
那么第三个(和第四个(之间最多只能有3个),至少1个
那么第四个(和第五个(之间最多只能有3个),至少1个
dp[i][j]:到第i+1个"("为止,有j个")"的方案数
k表示当前第i个"("和第i+1个"("之间有k个")"
dp[i][j] = sum(dp[i-1][j-k])
那么))))())))())))*(((((()(((()((,*号左边全是消不掉的),右边全是消不掉(,右边也就是上面讨论的情况,左边翻转一下也就是上面讨论情况,ans = ansl*ansr%MOD;

Parentheses Sequence微软编程笔试的更多相关文章

  1. hihocoder #1289 : 403 Forbidden (2016 微软编程笔试第二题)

    #1289 : 403 Forbidden 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi runs a web server. Sometimes ...

  2. 微软编程一小时 题目2: Longest Repeated Sequence

    题目2 : Longest Repeated Sequence 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of i ...

  3. Longest Repeated Sequence【微软编程一小时-题目2】

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a sequence of integers, A = a1, a2, ... an. A c ...

  4. hihocoder1489 Legendary Items (微软2017年预科生计划在线编程笔试)

    http://hihocoder.com/problemset/problem/1489 笔试题第一道,虽然说第一道都很水,但是我感觉这题不算特别水把..这道题我就卡住了我记得,tle,最后只有30分 ...

  5. 微软2017年预科生计划在线编程笔试 A Legendary Items

    思路: 获得第i(i = 0, 1, ..., n - 1)件物品的概率仅由公式p / (1 << i)决定,所以获得这i件物品之间是相互独立的.迭代计算获得所有i件物品的期望再求和即可. ...

  6. 【微软2017年预科生计划在线编程笔试 A】Legendary Items

    [题目链接]:https://hihocoder.com/problemset/problem/1489 [题意] 每轮游戏; 你一开始有p的概率获得超神标记; 如果这轮游戏你没获得超神标记; 那么你 ...

  7. 【微软2017年预科生计划在线编程笔试 B】Tree Restoration

    [题目链接]:https://hihocoder.com/problemset/problem/1490 [题意] 给你一棵树的以下信息: 1.节点个数 2.给出树的每一层从左到右的顺序每个节点的编号 ...

  8. 【微软2017年预科生计划在线编程笔试第二场 B】Diligent Robots

    [题目链接]:http://hihocoder.com/problemset/problem/1498 [题意] 一开始你有1个机器人; 你有n个工作; 每个工作都需要一个机器人花1小时完成; 然后每 ...

  9. 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack

    [题目链接]:http://hihocoder.com/problemset/problem/1497 [题意] 给你n个皇后; 然后问你其中能够互相攻击到的皇后的对数; 皇后的攻击可以穿透; [题解 ...

随机推荐

  1. bzoj3156 防御准备(斜率优化)

    Time Limit: 10 Sec  Memory Limit: 512 MB Input 第一行为一个整数N表示战线的总长度. 第二行N个整数,第i个整数表示在位置i放置守卫塔的花费Ai. Out ...

  2. ffmpeg的中文文档

    1. 概要 ffmpeg [global_options] {[input_file_options] -i INPUT_FILE} ... {[output_file_options] OUTPUT ...

  3. html a标签链接点击闪动问题解决

    <a href="#">链接点击会闪动,解决: 这三种都可以用:<a href="javascript:;"></a>< ...

  4. 搭建Keepalived+LNMP架构web动态博客 实现高可用与负载均衡

    环境准备: 192.168.193.80  node1 192.168.193.81 node2 关闭防火墙 [root@node1 ~]# systemctl stop firewalld #两台都 ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C

    题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...

  6. JuniorCTF - Web - blind

    题目链接 https://ctftime.org/task/7450 参考链接 https://github.com/Dvd848/CTFs/blob/master/2018_35C3_Junior/ ...

  7. HTML5 中list 和datalist实例

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. bzoj2325 [ZJOI2011]道馆之战 树链剖分+DP+类线段树最大字段和

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2325 题解 可以参考线段树动态维护最大子段和的做法. 对于线段树上每个节点 \(o\),维护 ...

  9. 神仙dcx出的一道题

    题目大意 \(\;\;\)在一个坐标系上, 以\((0, 0)\)为起点, 每走一步,可以从\((x,y)\)走到\((x+1,y),(x-1,y),(x,y+1),(x,y-1)\)中的一个点上, ...

  10. JUC并发工具类

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11449367.html java.util.concurrent及其子包,集中了Java并发的各种基础 ...