当前位置:网站首页>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;
}
}
边栏推荐
- About I double-checked and reviewed the About staff page, returning an industry question
- 【unity编译器扩展之模型动画拷贝】
- "No title"
- 在线中文姓名生成工具推荐
- 电子行业MES管理系统的主要功能与用途
- Redis visual management software Redis Desktop Manager2022
- Couple Holding Hands [Greedy & Abstract]
- IDEA file encoding modification
- 刘润直播预告 | 顶级高手,如何创造财富
- tiup telemetry
猜你喜欢

英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps

2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)

Mathematical Principles of Matrix

数据类型及输入输出初探(C语言)

子连接中的参数传递

简单的顺序结构程序(C语言)

【云原生--Kubernetes】Pod控制器
Handwritten Distributed Configuration Center (1)

The master teaches you the 3D real-time character production process, the game modeling process sharing

【Valentine's Day special effects】--Canvas realizes full screen love
随机推荐
SQL association table update
leetcode:269. 火星词典
软件测试面试题:关于自动化测试工具?
#yyds dry goods inventory #Switching equipment serious packet loss troubleshooting
【数据挖掘概论】数据挖掘的简单描述
ansible学习笔记分享-含剧本示例
2022 Hangzhou Electric Power Multi-School Session 3 Question L Two Permutations
ARC129E Yet Another Minimization 题解 【网络流笔记】
【LeetCode】图解 904. 水果成篮
找不到DiscoveryClient类型的Bean
Huggingface入门篇 II (QA)
2022多校第二场 K题 Link with Bracket Sequence I
2022牛客多校训练第二场 H题 Take the Elevator
Essential knowledge for entry-level 3D game modelers
Senior game modelers tell newbies, what are the necessary software for game scene modelers?
怎样进行在不改变主线程执行的时候,进行日志的记录
【论文笔记】—低照度图像增强—Unsupervised—EnlightenGAN—2019-TIP
How to automatically push my new articles to my fans (very simple, can't learn to hit me)
10 种常见的BUG分类
tiup update