当前位置:网站首页>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;
}边栏推荐
- The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
- How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
- The difference between new and malloc
- 三分钟学会基础k线图知识
- Brief description of grafana of # yyds dry goods inventory # Prometheus
- Pyldavis installation and use | attributeerror: module 'pyldavis' has no attribute' gensim '| visual results are exported as separate web pages
- KS006基于SSM实现学生成绩管理系统
- Modeling essays series 124 a simple coding method
- Altium designer measure distance (ctrl+m)
- [IVX junior engineer training course 10 papers] 06 database and services
猜你喜欢

We should make clear the branch prediction

Learn about servlets

Learning notes 25 - multi sensor front fusion technology

6-3漏洞利用-SSH环境搭建

Matlab uses resample to complete resampling

【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享

遊戲思考15:全區全服和分區分服的思考

matlab 使用 audioread 、 sound 读取和播放 wav 文件
![[IVX junior engineer training course 10 papers to get certificates] 0708 news page production](/img/ad/a1cb672d2913b6befd6d8779c993ec.jpg)
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production

PR second training
随机推荐
Basic concepts of machine learning
1218 square or round
How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
【LeetCode 43】236. The nearest common ancestor of binary tree
We should make clear the branch prediction
Have you stepped on the nine common pits in the e-commerce system?
This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
Edge computing accelerates live video scenes: clearer, smoother, and more real-time
Modeling essays series 124 a simple coding method
电子协会 C语言 1级 33 、奇偶数判断
[IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
What are the skills of spot gold analysis?
5g/4g pole gateway_ Smart pole gateway
matlab 使用 audioread 、 sound 读取和播放 wav 文件
Electronic Society C language level 1 32, calculate the power of 2
[rust web rokcet Series 1] Hello, world and get, post, put, delete
Learning notes 25 - multi sensor front fusion technology
Automatically browse pinduoduo products