当前位置:网站首页>[2022 Niuke multi School Game 2] k-link with bracket sequence I
[2022 Niuke multi School Game 2] k-link with bracket sequence I
2022-07-27 21:26:00 【Taoist priest has no Taoist temple】
Feeling after the game
After this fight, I went to prison ,K The question was thought to be false , I was thinking about combinatorics + Searching violently but without success . I didn't expect it to be DP, I feel a little loss , After all, the essence of dynamic regression is combinatorics , Not then DP Come out and make up the question now . By the way, write blog Make a deep impression .
Original link
General idea of the question :
Give a substring length and the original string length .
Another one Substring (A) , Let's ask how many Legal original string (B).
Their thinking :
DP thought : Set before i individual B At most, it matches to the front j individual A , That is to ask how much is possible B Number of alternatives
At this time, you also need to pay attention to using only i j Of the tag dp Not necessarily legal , therefore dp Designed in three dimensions Design another K To judge whether it is legal , The judgment idea is yes K individual The left parenthesis is not matched : Not zero , It's illegal .
State transition process :
Now consider If in front of i individual B What happens if you put an open parenthesis after it
We get the transfer equation :dp(i,j,k)->dp(i+1,j,k)
Think again , If A Of j+1 If it is a left parenthesis, it will match , If it's not, it can't match
If it is dp(i,j,k)->dp(i+1,j+1,k+1)
If not dp(i,j,k)->dp(i+1,j,k+1)
If it's right bracket I still need to see k Whether it is not zero , That is, there are unmatched left parentheses
AC Code :
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define Buff std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 205;
const int mod = 1e9 + 7;
int t, n, m;
int dp[N][N][N];
signed main()
{
Buff;
cin >> t;
while (t--)
{
cin >> n >> m;
string s;
cin >> s;
s = " " + s;
for (int i = 0; i <= m; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= i; k++) // k To i that will do
{
dp[i][j][k] = 0;
}
dp[0][0][0] = 1; // initialization There are no parentheses left in the empty sequence
for (int i = 0; i <= m; i++)
{
for (int j = 0; j <= n; j++)
{
for (int k = 0; k <= i; k++)
{
if (!dp[i][j][k])
continue;
if (s[j + 1] == '(')
dp[i + 1][j + 1][k + 1] = (dp[i + 1][j + 1][k + 1] + dp[i][j][k]) % mod;// The derived state transition equation
else
dp[i + 1][j][k + 1] = (dp[i + 1][j][k + 1] + dp[i][j][k]) % mod;
if (k)
if (s[j + 1] == ')')
dp[i + 1][j + 1][k - 1] = (dp[i + 1][j + 1][k - 1] + dp[i][j][k]) % mod;
else
dp[i + 1][j][k - 1] = (dp[i + 1][j][k - 1] + dp[i][j][k]) % mod;
}
}
}
cout << dp[m][n][0] << endl;
}
return 0;
}
边栏推荐
- 建筑云渲染的应用正在扩大,越来越多的行业急需可视化服务
- Rust变量特点
- Multi person collaborative development specification
- The application of building cloud rendering is expanding, and more and more industries are in urgent need of visualization services
- 用伪元素before实现元素的等比例缩放
- Sre related question answering
- Comprehensively design an oppe homepage -- Design of selected accessories on the page
- R language uses dplyr package to perform data aggregation statistics, calculate sliding window statistics, calculate sliding group mean, and merge the generated statistical data into the original data
- ORA-27300,ORA-27301,ORA-27302,ORA-27303,TNS-2518,TNS-12549,TNS-12560,TNS-00519等告警处理
- Get the method registered in the delegate
猜你喜欢

基于DSP 回传音通话降噪链路设计
![Paper appreciation [emnlp18] dynamic oracles for top-down and middle order move in reduction component parsing](/img/bf/5244eafd927ae990551a59dfa7e863.png)
Paper appreciation [emnlp18] dynamic oracles for top-down and middle order move in reduction component parsing

Feixin died in 2022: a good hand of China Mobile was broken, and 500million users became "zombies"

API gateway introduction

Characteristics of exonuclease in Worthington venom and related literature

Report design - how to make your powerbi Kanban brilliant?

综合设计一个OPPE主页--页面的精选配件的设计

Dobot magician robot arm - Introduction

Win11用户名和密码备份方法

puzzle(021)消除问题
随机推荐
QModbus库使用,并作为ROS节点发布话题及程序CMakelist编写
Automatic classification of e-commerce UGC pictures using Baidu PaddlePaddle easydl
Rust变量特点
What are the product performances of industrial Ethernet switches?
How to speed up the memory database through special data type index
What is the value of digital factory management system
LabVIEW learning note 9: capture the "value change" event generated by the program modifying the control value
数字化工厂管理系统有哪些价值
ADB ~ 隐藏或禁用状态栏和虚拟按键
Worthington磷脂酶A2研究丨磷脂酰胆碱2-乙酰水解酶
R language uses dplyr package to perform data aggregation statistics, calculate sliding window statistics, calculate sliding group mean, and merge the generated statistical data into the original data
The maximum recommended number of rows for MySQL is 2000W. Is it reliable?
访问共享文件夹时提示“因为文件共享不安全 SMB1协议”请使用SMB2协议
报表设计丨如何让你的PowerBI看板出彩?
Thinking about SLA of cloud computing
puzzle(002)内固、外固、哈密顿
Smart Internet ran out of China's "acceleration", and the market reshuffle behind the 26.15% carrying rate
Paper appreciation [emnlp18] dynamic oracles for top-down and middle order move in reduction component parsing
新来CTO 强烈禁止使用Calendar...,那用啥?
Understanding of reg type variables in Verilog HDL