当前位置:网站首页>POJ - 2955 brackets interval DP
POJ - 2955 brackets interval DP
2022-04-23 06:21:00 【Bzdhxs_ nt】
Ideas
Classical interval d p dp dp The topic of transfer mode has been given
consider d p [ i ] [ j ] dp[i][j] dp[i][j] It means that [ i , j ] [i,j] [i,j] The number of bracket pairs that can be matched in the interval
State shift
f [ i ] [ j ] = f [ i + 1 ] [ j − 1 ] + c h e c k ( i , j ) ; f[i][j] = f[i+1][j-1] + check(i,j); f[i][j]=f[i+1][j−1]+check(i,j);
f [ i ] [ j ] = m a x ( f [ i ] [ j ] , f [ i ] [ k ] + f [ k + 1 ] [ j ] ) ; f[i][j] = max(f[i][j],f[i][k]+f[k+1][j]); f[i][j]=max(f[i][j],f[i][k]+f[k+1][j]);
Code
int f[110][110];
string s;
bool chk(int i,int j){
if((s[i] == '[' && s[j] == ']')||(s[i]=='(' && s[j]==')')) return true;
return false;
}
signed main()
{
while(cin >> s){
if(s == "end") break;
mem(f,0);
int le = s.size();
forr(len,2,le){
for(int i = 0;i+len-1<le;i++){
int j = i+len-1;
f[i][j] = f[i+1][j-1]+chk(i,j);
for(int k = i;k<j;k++) f[i][j] = max(f[i][j],f[i][k]+f[k+1][j]);
}
}
cout << f[0][le-1]*2 << endl;
}
return 0;
版权声明
本文为[Bzdhxs_ nt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210617219258.html
边栏推荐
- Understanding and use of tp50, tp90 and tp99
- Numpy common function table sorting of data processing
- 线性代数第一章-行列式
- Pytoch -- data loading and processing
- Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
- Supply chain service terms
- Solution record of slow access speed of SMB service in redhat6
- Techniques et principes de détection
- Collection and map thread safety problem solving
- Protected (members modified by protected are visible to this package and its subclasses)
猜你喜欢

Filebrowser realizes private network disk

Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving

Practical operation - Nacos installation and configuration

检测技术与原理

图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration

A general U-shaped transformer for image restoration

卡尔曼滤波与惯性组合导航

Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()

Pytoch -- data loading and processing

Implementation of displaying database pictures to browser tables based on thymeleaf
随机推荐
Chapter 4 of line generation - linear correlation of vector systems
Failure to deliver XID in Seata distributed transaction project
Practical operation - Nacos installation and configuration
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
2. Average length of words
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
A general U-shaped transformer for image restoration
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
5.The Simple Problem
container
The user name and password of users in the domain accessing the samba server outside the domain are wrong
Collection and map thread safety problem solving
自動控制(韓敏版)
[transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package
Filebrowser realizes private network disk
PHP processing JSON_ Decode() parses JSON stringify
11.a==b?
Example of ticket selling with reentrant lock
Treatment of tensorflow sequelae - simple example record torch utils. data. dataset. Picture dimension problem when rewriting dataset