当前位置:网站首页>[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
边栏推荐
- E-R draw clear content
- Multi site high availability deployment
- Vscode下中文乱码问题
- VS Code配置问题
- Global and Chinese market of wire loop, 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for conventional rubber track 2022-2028: Research Report on technology, participants, trends, market size and share
- AR system summary harvest
- Li Kou daily one question brushing summary: binary tree chapter (continuous update)
- CarSim problem failed to start solver: path_ ID_ OBJ(X) was set to Y; no corresponding value of XXXXX?
- On the back door of deep learning model
猜你喜欢

利用超球嵌入来增强对抗训练

针对语义分割的真实世界的对抗样本攻击

CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现

用于类别增量学习的动态可扩展表征 -- DER

应对长尾分布的目标检测 -- Balanced Group Softmax

Data reverse attack under federated learning -- gradinversion

Replace self attention with MLP

How to wrap qstring strings

STM32疑难杂症之ST-LINK Connection error INVALID ROM TABLE

Use C language to receive JSON strings
随机推荐
Eklavya -- infer the parameters of functions in binary files using neural network
Causes of laptop jam
OpenCV常用方法出处链接(持续更新)
Longest isometric subsequence
包图画法注意规范
Replace convolution with full connection layer -- repmlp
Global and Chinese market of wire loop, 2022-2028: Research Report on technology, participants, trends, market size and share
学习写文章格式
Real world anti sample attack against semantic segmentation
Embedding malware into neural networks
Animation synchronization of CarSim real-time simulation
Opencv's experience of confusing X and Y coordinates
I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
Global and Chinese market of recovery equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Static library and dynamic library
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
OpenCV关于x,y坐标容易混淆的心得
The internal network of the server can be accessed, but the external network cannot be accessed
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
How to uninstall SQL Server cleanly