Bracket Sequence

题目链接
题意 :
给定括号的对数和括号的种类求出最后合法序列的数量
思路 :
如果只有一种括号序列就可以直接用卡特兰数
多种匹配的括号可以转换成同一种括号

最后结果为kNk^{N}kN x C2NNC_{2N}^{N}C2NN​ / (n + 1)
AC代码 :

#include <iostream>
#include <map>
#include <cstring>
#include <algorithm>
#include <math.h>#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)using namespace std;
typedef long long LL;
const int N = 200010, mod = 1e9 + 7;int n,k;
int fact[N], infact[N];int ksm(int a, int k) {int res = 1;while (k) {if (k & 1) res = (LL)res * a % mod;a = (LL)a * a % mod;k >>= 1;}return res % mod;
}void init() {fact[0] = infact[0] = 1;for (int i = 1; i < N; i++) {fact[i] = (LL)fact[i - 1] * i % mod;infact[i] = (LL)infact[i - 1] * ksm(i, mod - 2) % mod;}
}int main() {init();IOS;cin >> n >> k;LL res = (LL)fact[2 * n] * infact[n] % mod * infact[n] % mod * ksm(n + 1, mod - 2) % mod;LL ans = ksm(k,n);cout << res * ans % mod << endl;return 0;
}

Bracket Sequence相关推荐

  1. Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈

    C. Replace To Make Regular Bracket Sequence 题目连接: http://www.codeforces.com/contest/612/problem/C De ...

  2. Codeforces Beta Round #5 C. Longest Regular Bracket Sequence 栈/dp

    C. Longest Regular Bracket Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  3. Codeforces 524F And Yet Another Bracket Sequence 哈希

    And Yet Another Bracket Sequence 枚举起点, 增加的(肯定在最前面, 增加的)肯定在最后面, 比字典序用hash, 卡了自然溢出.. #include<bits/ ...

  4. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  5. CF思维联系–CodeForces -224C - Bracket Sequence

    ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...

  6. CodeForces - 224C. Bracket Sequence (栈模拟)简单做法

    A bracket sequence is a string, containing only characters "(", ")", "[&quo ...

  7. cf1556Compressed Bracket Sequence

    cf1556Compressed Bracket Sequencex 题意: 给你n个数,奇数位置上的数表示左括号的数量,偶数位置上的数表示右括号的数量.问有多少个[l,r]是满足括号匹配的 题解: ...

  8. LS 24 Bracket sequence(DP)

    Bracket sequence Given string s made up with (, ), ?, count the way to substitude ? with ( or ) to f ...

  9. Codeforces 26B. Regular Bracket Sequence

    Codeforces 26B. Regular Bracket Sequence 传送门:https://codeforces.com/problemset/problem/26/B 题目大意: 其实 ...

  10. C. Compressed Bracket Sequence

    William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to ...

最新文章

  1. C语言第一次博客作业——输入输出格式
  2. java登录界面命令_Java命令行界面(第30部分):观察
  3. 2021 最新 IDEA集成Gitee、Gitee迁移GitHub【图文讲解】
  4. selinux + sudo +ssh +passwd
  5. 90-50-010-源码-hbase的rowkey设计
  6. DDNS-动态域名解析服务
  7. 一个核心系统 3 万多行代码的重构之旅
  8. 在Ubuntu上使用apt-get安装MySQL+安全优化
  9. js动态添加HTML css失效,JS动态添加元素和设置其样式问题
  10. Exchange的邮箱创建与使用
  11. 计算机win10+上锁,win10系统给电脑屏幕上锁的操作方法
  12. 1. 简明误差卡尔曼滤波器(ESKF)及其推导过程
  13. echarts树状图怎么设置主节点和子节点的距离_教你秒懂CAD出图比例正确设置技巧...
  14. Error occured processing XML 'Cannot find class [springmvc.extention.BeanArgumentResolver]'.
  15. bugku---game1
  16. hive sql 实现姓名手机号证件号脱敏
  17. PN6005电动车控制器芯片DC-DC降压芯片
  18. 遍历字典,以及遍历列表总结
  19. 当前服务器在线人数,显示当前在线人数
  20. 干货 | 快速融入云原生,携程开源 Dubbo for Go 版本

热门文章

  1. 数据库SQL综合分析题
  2. 大起大落,蚂蚁上市被叫停,蚂蚁的程序员们怎么样了?
  3. c语言递归调用次数,C语言中的递归调用
  4. c语言 伪随机数程序,C语言的伪随机数
  5. 调用API获取深圳市的公开大数据集——以高速公路ETC入深圳数据为例
  6. 【程序人生】改不完的bug,写不完的需求,爬不完的坑
  7. 保罗·多兰《设计幸福》阅读笔记
  8. html和css的小结
  9. 2013年 第4届 蓝桥杯 Java B组 省赛解析及总结
  10. css怎样让导航词语间隔,css - 导航分隔符