当前位置:网站首页>2022 Multi-school Second Session K Question Link with Bracket Sequence I
2022 Multi-school Second Session K Question Link with Bracket Sequence I
2022-08-05 00:21:00 【雨肯定】
题目链接
题目大意
Given us a length of n n n的括号序列,and tells us it is a length of m m mA substring of a valid parentheses sequence,Ask us that this length is m m mHow many cases of parenthesis sequences are there?
题解
考虑DP,设 f i , j , k f_{i,j,k} fi,j,k 表示考虑 b b b串的前i个字符,和 a a aThe longest common subsequence length of the string is j j j,左括号比右括号多 k k k,Each time the enumeration is shifted, whether it is an opening or closing parenthesis,最后答案即为 f [ m ] [ n ] [ 0 ] f_{[m][n][0]} f[m][n][0].
代码
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 210;
const int mod = 1e9 + 7;
int f[maxn][maxn][maxn];
int main()
{
int t; cin >> t;
while(t --)
{
memset(f, 0, sizeof f);
int n, m; cin >> n >> m;
string s; cin >> s;
s = ' ' + s;
f[0][0][0] = 1;
for(int i = 1; i <= m; i ++){
for(int j = 0; j <= n && j <= i; j ++){
for(int k = 0; k <= i; k ++){
if(k) {
if(j && s[j] == '(') f[i][j][k] = (f[i][j][k] + f[i - 1][j - 1][k - 1]) % mod;
else f[i][j][k] = (f[i][j][k] + f[i - 1][j][k - 1]) % mod;
}
if(k != m) {
if(!j || s[j] == '(') f[i][j][k] = (f[i][j][k] + f[i - 1][j][k + 1]) % mod;
else f[i][j][k] = (f[i][j][k] + f[i - 1][j - 1][k + 1]) % mod;
}
}
}
}
cout << f[m][n][0] << endl;
}
}
边栏推荐
- Chinese and Japanese color style
- 软件质量评估的通用模型
- 2022杭电多校训练第三场 1009 Package Delivery
- Metasploit-域名上线隐藏IP
- [Cloud Native--Kubernetes] Pod Controller
- oracle创建表空间
- SV 类的虚方法 多态
- what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
- 日志(logging模块)
- 论文解读( AF-GCL)《Augmentation-Free Graph Contrastive Learning with Performance Guarantee》
猜你喜欢
Mathematical Principles of Matrix
jenkins send mail system configuration
2 用D435i运行VINS-fusion
What is next-generation modeling (with learning materials)
KT148A voice chip ic working principle and internal architecture description of the chip
oracle创建用户
【idea】idea配置sql格式化
redis可视化管理软件Redis Desktop Manager2022
怎样进行在不改变主线程执行的时候,进行日志的记录
数据类型及输入输出初探(C语言)
随机推荐
leetcode经典例题——单词拆分
2022多校第二场 K题 Link with Bracket Sequence I
D - I Hate Non-integer Number (选数的计数dp
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
Mysql_12 多表查询
TinyMCE禁用转义
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
Mysql_13 事务
阅读笔记:如何理解DevOps?
怎样进行在不改变主线程执行的时候,进行日志的记录
【unity编译器扩展之模型动画拷贝】
图解 Canvas 入门
About I double-checked and reviewed the About staff page, returning an industry question
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
KT148A voice chip ic working principle and internal architecture description of the chip
网站最终产品页使用单一入口还是多入口?
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
QSunSync 七牛云文件同步工具,批量上传
10 种常见的BUG分类