当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢

怎样进行在不改变主线程执行的时候,进行日志的记录

Modelers experience sharing: model study method

MAUI Blazor 权限经验分享 (定位,使用相机)

图解 Canvas 入门

STC89C52RC的P4口的应用问题

Getting started with 3D modeling for games, what modeling software can I choose?

【LeetCode】双指针题解汇总

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

进程间通信和线程间通信

The master teaches you the 3D real-time character production process, the game modeling process sharing
随机推荐
软件测试面试题:关于自动化测试工具?
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
NMS原理及其代码实现
tensor.nozero(), mask, [mask]
日志(logging模块)
软件测试面试题:请你分别画出 OSI 的七层网络结构图和 TCP/IP 的四层结构图?
Huggingface入门篇 II (QA)
Chinese and Japanese color style
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
软件测试面试题:做好测试计划的关键是什么?
Handwritten Distributed Configuration Center (1)
what?测试/开发程序员要被淘汰了?年龄40被砍到了32?一瞬间,有点缓不过神来......
The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
Mysql based
《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
TinyMCE disable escape
软件测试面试题:BIOS, Fat, IDE, Sata, SCSI, Ntfs windows NT?
导入JankStats检测卡帧库遇到问题记录
僵尸进程和孤儿进程
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?