当前位置:网站首页>Link with bracket sequence I (state based multidimensional DP)
Link with bracket sequence I (state based multidimensional DP)
2022-07-28 21:06:00 【to cling】
" Weilai cup "2022 Niuke summer multi school training camp 2
Problem
Given a length of n The bracket sequence of a, ask : The composition length is m( n ≤ m n \leq m n≤m) The legal bracket sequence of b How many options are there .
Solution
f [ i ] [ j ] [ k ] : The length is i Sequence b contain a Before j individual , And there is k There are no matching schemes in the left parenthesis f[i][j][k]: The length is i Sequence b contain a Before j individual , And there is k There are no matching schemes in the left parenthesis f[i][j][k]: The length is i Sequence b contain a Before j individual , And there is k There are no matching schemes in the left parenthesis
- a [ j ] = ′ ( ′ a[j] = ~'(' a[j]= ′(′
When b [ i ] = ′ ( ′ f [ i − 1 ] [ j − 1 ] [ k − 1 ] → f [ i ] [ j ] [ k ] b[i] = ~'('~~~~f[i - 1][j - 1][k - 1] \to f[i][j][k] b[i]= ′(′ f[i−1][j−1][k−1]→f[i][j][k]
When b [ i ] = ′ ) ′ f [ i − 1 ] [ j ] [ k + 1 ] → f [ i ] [ j ] [ k ] b[i] = ~')'~~~~f[i - 1][j][k + 1] \to f[i][j][k] b[i]= ′)′ f[i−1][j][k+1]→f[i][j][k] - a [ j ] = ′ ) ′ a[j] = ~')' a[j]= ′)′
When b [ i ] = ′ ( ′ f [ i − 1 ] [ j ] [ k − 1 ] → f [ i ] [ j ] [ k ] b[i] = ~'('~~~~f[i - 1][j][k - 1] \to f[i][j][k] b[i]= ′(′ f[i−1][j][k−1]→f[i][j][k]
When b [ i ] = ′ ) ′ f [ i − 1 ] [ j − 1 ] [ k + 1 ] → f [ i ] [ j ] [ k ] b[i] = ~')'~~~~f[i - 1][j - 1][k + 1] \to f[i][j][k] b[i]= ′)′ f[i−1][j−1][k+1]→f[i][j][k]
Code
int n, m;
ll f[202][202][202];
int main()
{
IOS;
int T; cin >> T;
while (T--)
{
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 <= min(i, n); j++)
for (int k = 0; k <= i; k++)
{
f[i][j][k] = 0;
if (j == 0)
{
if(k) f[i][j][k] += f[i - 1][j][k - 1];// The first i Bit is left parenthesis
f[i][j][k] += f[i - 1][j][k + 1];// The first i Bit is a right parenthesis
}
else if (s[j] == '(')
{
if(j && k) f[i][j][k] += f[i - 1][j - 1][k - 1];// The first i Bit is left parenthesis
f[i][j][k] += f[i - 1][j][k + 1];// The first i Bit is a right parenthesis
}
else
{
if(k) f[i][j][k] += f[i - 1][j][k - 1];// The first i Bit is left parenthesis
if(j) f[i][j][k] += f[i - 1][j - 1][k + 1];// The first i Bit is a right parenthesis
}
f[i][j][k] %= mod;
}
cout << f[m][n][0] << endl;
}
return 0;
}
边栏推荐
- 1 Introduction to command mode
- Moco V2: further upgrade of Moco series
- Unity - Fundamentals of 3D mathematics
- Network layer performance test
- The average altitude is 4000 meters! We built a cloud on the roof of the world
- Report redirect after authorized login on wechat official account_ The problem of wrong URI parameters
- How to modify the ID of NetApp expansion enclosure disk shelf
- Database -- use of explain
- C foundation 8-reflection and dependency injection
- What is low code? Which platforms are suitable for business personnel? Is it reliable to develop the system?
猜你喜欢

Unity foundation 2 editor expansion

Color finder actual combat (QT including source code)

After Europe, it entered Japan and South Korea again, and the globalization of Pico consumer VR accelerated

Moco V2: further upgrade of Moco series

Integrating database Ecology: using eventbridge to build CDC applications

Explain in detail the rays and radiographic testing in unity

How do we do full link grayscale on the database?

Unity foundation 6-rotation

向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!

Read the recent trends of okaleido tiger and tap the value and potential behind it
随机推荐
How to use redis to realize things and locks?
图书馆借阅系统「建议收藏」
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
Use order by to sort
一名在读研究生的自白:我为什么会沉迷于openGauss 社区?
Ask if you don't understand, and quickly become an advanced player of container service!
Unity - Fundamentals of 3D mathematics
The EMC vnx5200 fault light is on, but there is no hardware fault prompt
第六七八次作业
数据库--explain的使用
Space shooting Lesson 11: sound and music
Network layer performance test
MoCo V2:MoCo系列再升级
Cause analysis of restart of EMC cx4-120 SPB controller
4.1 Member的各种调用方式
作业 ce
Introduction to singleton mode
C # basic 7-iterator and coroutine
oracle如何导出数据(oracle如何备份数据库)