当前位置:网站首页>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;
}
边栏推荐
- 取色器实战(Qt含源码)
- 什么是 CI/CD? | 实现更快更好的软件交付
- How to use redis to realize things and locks?
- Zcmu--5066: dark corridor
- 【云原生】什么是 CI/CD ? | 摆平交付障碍的 CI/CD
- Prize essay solicitation | 2022 cloud native programming challenge draft activity opens
- 2 enjoy yuan mode
- Interesting pictures and words
- Introduction to blue team: efficiency tools
- Introduction to redis I: redis practical reading notes
猜你喜欢

mysql梳理复习内容--附思维导图

The 678th operation

Lvs+keepalived high availability deployment practical application

Confusing knowledge points of software designer examination

Deit: attention can also be distilled

Read the recent trends of okaleido tiger and tap the value and potential behind it

Prize essay solicitation | 2022 cloud native programming challenge draft activity opens

Interesting pictures and words

Meaning of disk status of EMC DataDomain

Efficientformer: lightweight vit backbone
随机推荐
《软件设计师考试》易混淆知识点
dll反编译(反编译加密dll)
ctfshow 网络迷踪做题记录(2)
58岁安徽人,干出瑞士今年最大IPO 投资界
Database -- use of explain
Space shooting Lesson 13: explosion effect
Explain the imported 3D model in unity
C # basic 7-iterator and coroutine
广和通&高通物联网技术开放日成功举办
Unity foundation 4 common plug-ins
Space game Lesson 12: shield
Unit editor details
程序员最大的浪漫~
It is not only convenient, safe + intelligent, but also beautiful. Fluorite releases the Big Dipper face lock dl30f and Aurora face video lock y3000fv
protobuf 中基础数据类型的读写
有奖征文 | 2022 云原生编程挑战赛征稿活动开启
PostgreSQL数据库删库前是不是需要把所有连接断开才能删除?
Prize essay solicitation | 2022 cloud native programming challenge draft activity opens
Unity foundation 1 - event execution sequence, custom events
Cause analysis of restart of EMC cx4-120 SPB controller