当前位置:网站首页>1222. Password dropping (interval DP, bracket matching)
1222. Password dropping (interval DP, bracket matching)
2022-07-02 01:45:00 【seez】

It can be seen that it is a bracket match / Template question of the longest palindrome subsequence

initialization : All defined as 0
The border : Because a single character is also a palindrome subsequence ,dp[i][i]=1
State calculation / subset division : According to whether the characters at both ends are in the longest palindrome subsequence , It can be divided into the following four subsets without repetition and leakage
- s[i] and s[j] All in palindrome subsequence dp[i][j]=max(dp[i+1][j-1]+2)
- s[i] In palindrome subsequence dp[i][j]=max(dp[i][j-1])
- s[j] In palindrome subsequence dp[i][j]=max(dp[i+1][j])
- s[i]s[j] Are not in the palindrome subsequence dp[i][j]=max(dp[i-1][j-1])
According to the state representation ,si In palindrome subsequence , It can be considered as a collection dp[i][j-1] in
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1005;
int dp[N][N];
int main()
{
string s;
cin>>s;
s=" "+s;
int n=s.size();
for(int i=1;i<=n;i++)
dp[i][i]=1;
for(int len=2;len<=n;len++)
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
dp[i][j]=max(dp[i+1][j],dp[i][j-1]);
if(s[i]==s[j])
dp[i][j]=dp[i+1][j-1]+2;
}
cout<<n-dp[1][n]-1;
return 0;
}边栏推荐
- Failed to transform file 'xxx' to match attributes
- How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
- Study note 2 -- definition and value of high-precision map
- Laravel artisan 常用命令
- 牛客网——华为题库(51~60)
- 浅浅了解Servlet
- I Brief introduction of radio energy transmission technology
- 游戏思考15:全区全服和分区分服的思考
- [rust web rokcet Series 2] connect the database and add, delete, modify and check curd
- Brief introduction to the development of mobile network
猜你喜欢

【LeetCode 43】236. The nearest common ancestor of binary tree

Discussion on the idea of platform construction
![[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing](/img/ba/dcb276768b1a9cc84099f093677d29.png)
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing

The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
![[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility](/img/8b/e51867cfe9d200ac385e1d1f01e4b3.jpg)
[Obsidian] wechat is sent to Obsidian using remotely save S3 compatibility

如何远程、在线调试app?

Volume compression, decompression

Matlab uses audioread and sound to read and play WAV files

Liteos learning - first knowledge of development environment

6-2 vulnerability exploitation - inevitable problems of FTP
随机推荐
如何用一款产品推动「品牌的惊险一跃」?
Based on configured schedule, the given trigger will never fire
Makefile simple induction
ECS project deployment
Unity AssetBundle subcontracting
电子协会 C语言 1级 33 、奇偶数判断
卷積神經網絡(包含代碼與相應圖解)
Android high frequency network interview topic must know and be able to compare Android development environment
uTools
There are spaces in the for loop variable in the shell -- IFS variable
The role of artificial intelligence in network security
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
机器学习基本概念
Matlab uses audioread and sound to read and play WAV files
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
It's already 30. Can you learn programming from scratch?
6-3漏洞利用-SSH环境搭建
[rust web rokcet Series 1] Hello, world and get, post, put, delete
[IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
并发编程的三大核心问题