当前位置:网站首页>[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
边栏推荐
- [learning notes] matlab self compiled Gaussian smoother +sobel operator derivation
- Static library and dynamic library
- 静态库和动态库
- Real world anti sample attack against semantic segmentation
- install. IMG production method
- Global and Chinese market of medicine cabinet 2022-2028: Research Report on technology, participants, trends, market size and share
- 力扣方法总结:查找类
- Carla-ue4editor import Roadrunner map file (nanny level tutorial)
- 稀疏矩阵存储
- Find and rfind methods in string
猜你喜欢
Introduction to parameters of CarSim pavement 3D shape file
Installation and use of simple packaging tools
Animation synchronization of CarSim real-time simulation
On the confrontation samples and their generation methods in deep learning
OpenCV 6.4 中值滤波器的使用
简易打包工具的安装与使用
Carsim 学习心得-粗略翻译1
Use C language to receive JSON strings
Opencv3 6.3 reduced pixel sampling with filters
Using super ball embedding to enhance confrontation training
随机推荐
Comparison between setTimeout and requestanimationframe (page refresh)
用于类别增量学习的动态可扩展表征 -- DER
Open3d learning note 4 [surface reconstruction]
C语言的库函数
JVM instructions
我的vim配置文件
静态库和动态库
[C # note] the data in DataGridView saved in WinForm is excel and CSV
業務架構圖
Summary of one question per day: stack and queue (continuously updated)
Summary of solving the Jetson nano installation onnx error (error: failed building wheel for onnx)
On the confrontation samples and their generation methods in deep learning
Real world anti sample attack against semantic segmentation
Data reverse attack under federated learning -- gradinversion
Rhel7 operation level introduction and switching operation
服务器的内网可以访问,外网却不能访问的问题
Global and Chinese market of tillage finishing machines 2022-2028: Research Report on technology, participants, trends, market size and share
OpenCV3 6.2 低通滤波器的使用
王-课外单词
Matlab数学建模工具