当前位置:网站首页>[dynamic planning] p4170: coloring (interval DP)
[dynamic planning] p4170: coloring (interval DP)
2022-07-02 08:14:00 【muse_ age】





initialization :
Because of the demand minimum value , all dp Initialize to INF
When the interval length is 1 when ,dp by 1
Enumerate small intervals first when enumerating
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int dp[51][51];
int main(){
string s;
cin>>s;
int n=s.size();
memset(dp,0x3f3f,sizeof(dp));
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;
if(s[i-1]==s[j-1]){
dp[i][j]=min(dp[i+1][j],dp[i][j-1]);
}
else{
for(int k=i;k<j;k++){
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
}
}
}
}
cout<<dp[1][n];
}Refer to the explanation of the question :
Answer key P4170 【[CQOI2007] Coloring 】 - dzz The blog of - Luogu blog
边栏推荐
- Backup, recovery and repair of XFS file system
- Using transformer for object detection and semantic segmentation
- My VIM profile
- 力扣每日一题刷题总结:栈与队列篇(持续更新)
- Meta Learning 简述
- Vs code configuration problem
- SQL server如何卸载干净
- Global and Chinese market of snow sweepers 2022-2028: Research Report on technology, participants, trends, market size and share
- How to back up the configuration before the idea when reinstalling the idea
- Eklavya -- infer the parameters of functions in binary files using neural network
猜你喜欢

Installation and use of simple packaging tools

Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)

针对tqdm和print的顺序问题

Carla-ue4editor import Roadrunner map file (nanny level tutorial)

CarSim problem failed to start solver: path_ ID_ OBJ(X) was set to Y; no corresponding value of XXXXX?

Use of OpenCV 6.4 median filter

Animation synchronization of CarSim real-time simulation

Principes fondamentaux de la théorie musicale (brève introduction)

图像增强的几个方法以及Matlab代码

C语言实现XML生成解析库(XML扩展)
随机推荐
Global and Chinese markets for conventional rubber track 2022-2028: Research Report on technology, participants, trends, market size and share
How gensim freezes some word vectors for incremental training
Embedding malware into neural networks
業務架構圖
Open3d learning notes II [file reading and writing]
MySQL optimization
Opencv3 6.3 reduced pixel sampling with filters
Constant pointer and pointer constant
Matlab数学建模工具
[learning notes] numerical differentiation of back error propagation
Sqlyog remote connection to MySQL database under centos7 system
C # connect to MySQL database
Specification for package drawing
Brief introduction of prompt paradigm
My VIM profile
Meta Learning 简述
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
Real world anti sample attack against semantic segmentation
OpenCV 6.4 中值滤波器的使用
Array and string processing, common status codes, differences between PHP and JS (JS)