当前位置:网站首页>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
边栏推荐
- Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
- The problem that the page will refresh automatically after clicking the submit button on the form is solved
- Troubleshooting of data deleted and reappeared problems
- Create binary tree
- Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
- Stability building best practices
- 7.Domino piling
- 图像恢复论文简记——Uformer: A General U-Shaped Transformer for Image Restoration
- Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
- Collection and map thread safety problem solving
猜你喜欢
RPC must know and know
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
A general U-shaped transformer for image restoration
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
Explain of MySQL optimization
A sharp tool to improve work efficiency
Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
线性代数第一章-行列式
String notes
随机推荐
MySQL occasional Caton
Rsync for file server backup
Pytorch notes - complete code for linear regression & manual or automatic calculation of gradient code comparison
自动控制(韩敏版)
线性代数第一章-行列式
container
线性代数第二章-矩阵及其运算
Consistent hash algorithm used for redis cache load balancing
线性代数第三章-矩阵的初等变换与线性方程组
自动控制原理知识点整合归纳(韩敏版)
Code neat way to learn
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
Solution record of slow access speed of SMB service in redhat6
Common sense of thread pool
Generate excel template (drop-down selection, multi-level linkage)
Stability building best practices
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
Example of ticket selling with reentrant lock
Pytorch learning record (7): skills in processing data and training models
JDBC operation transaction