当前位置:网站首页>[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
边栏推荐
- 力扣每日一题刷题总结:二叉树篇(持续更新)
- 业务架构图
- 樂理基礎(簡述)
- SQL operation database syntax
- CarSim problem failed to start solver: path_ ID_ OBJ(X) was set to Y; no corresponding value of XXXXX?
- A brief analysis of graph pooling
- Dynamic extensible representation for category incremental learning -- der
- Graph Pooling 简析
- Sparse matrix storage
- OpenCV3 6.3 用滤波器进行缩减像素采样
猜你喜欢

MySQL优化

Using transformer for object detection and semantic segmentation
![Open3d learning notes 1 [first glimpse, file reading]](/img/68/68ea87817dbf788591216a32c9375b.png)
Open3d learning notes 1 [first glimpse, file reading]

Target detection for long tail distribution -- balanced group softmax

Installation and use of simple packaging tools

C language implements XML generation and parsing library (XML extension)

MySQL optimization

Replace self attention with MLP

It's great to save 10000 pictures of girls

Matlab mathematical modeling tool
随机推荐
Use of opencv3 6.2 low pass filter
Carla-UE4Editor导入RoadRunner地图文件(保姆级教程)
C语言的库函数
MySQL optimization
CarSim problem failed to start solver: path_ ID_ OBJ(X) was set to Y; no corresponding value of XXXXX?
Open3d learning note 5 [rgbd fusion]
Animation synchronization of CarSim real-time simulation
Chinese garbled code under vscade
稀疏矩阵存储
Summary of one question per day: String article (continuously updated)
Replace self attention with MLP
Vscode下中文乱码问题
Sqlyog remote connection to MySQL database under centos7 system
Meta Learning 简述
Erase method in string
[learning notes] matlab self compiled Gaussian smoother +sobel operator derivation
Force deduction method summary: find classes
AR系统总结收获
深入理解JVM
Matlab数学建模工具