当前位置:网站首页>[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
边栏推荐
- Use of OpenCV 6.4 median filter
- How gensim freezes some word vectors for incremental training
- Chinese garbled code under vscade
- 利用超球嵌入来增强对抗训练
- Global and Chinese markets for Salmonella typhi nucleic acid detection kits 2022-2028: Research Report on technology, participants, trends, market size and share
- Carsim-实时仿真的动画同步问题
- 力扣方法总结:双指针
- 学习写文章格式
- OpenCV常用方法出处链接(持续更新)
- Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
猜你喜欢

Replace convolution with full connection layer -- repmlp

11月24号,我们为“满月”庆祝

In the era of short video, how to ensure that works are more popular?

It's great to save 10000 pictures of girls

樂理基礎(簡述)

Real world anti sample attack against semantic segmentation

使用C#语言来进行json串的接收

Carsim 学习心得-粗略翻译1

针对tqdm和print的顺序问题

包图画法注意规范
随机推荐
C # connect to MySQL database
OpenCV3 6.3 用滤波器进行缩减像素采样
Chinese garbled code under vscade
Global and Chinese market of electric cheese grinder 2022-2028: Research Report on technology, participants, trends, market size and share
Backup, recovery and repair of XFS file system
Graph Pooling 简析
Use of OpenCV 6.4 median filter
Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
Organigramme des activités
Force deduction method summary: double pointer
Introduction to parameters of CarSim pavement 3D shape file
Constant pointer and pointer constant
CarSim problem failed to start solver: path_ ID_ OBJ(X) was set to Y; no corresponding value of XXXXX?
Dynamic extensible representation for category incremental learning -- der
[learning notes] matlab self compiled image convolution function
STM32疑难杂症之ST-LINK Connection error INVALID ROM TABLE
Using C language to realize MySQL true paging
The internal network of the server can be accessed, but the external network cannot be accessed
利用超球嵌入来增强对抗训练
Data reverse attack under federated learning -- gradinversion