当前位置:网站首页>[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
边栏推荐
- Carsim-实时仿真的动画同步问题
- Global and Chinese markets of tilting feeders 2022-2028: Research Report on technology, participants, trends, market size and share
- Embedding malware into neural networks
- On November 24, we celebrate the "full moon"
- Open3d learning notes 1 [first glimpse, file reading]
- I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
- In the era of short video, how to ensure that works are more popular?
- Get the width and height of the screen in real time (adaptive)
- Introduction to parameters of CarSim pavement 3D shape file
- SQLyog远程连接centos7系统下的MySQL数据库
猜你喜欢
Carsim-路面3D形状文件参数介绍
樂理基礎(簡述)
It's great to save 10000 pictures of girls
Simply test the two different data transmission methods of content length and chunked
C language implements XML generation and parsing library (XML extension)
Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
The internal network of the server can be accessed, but the external network cannot be accessed
Carla-ue4editor import Roadrunner map file (nanny level tutorial)
针对tqdm和print的顺序问题
Using transformer for object detection and semantic segmentation
随机推荐
Global and Chinese market of snow sweepers 2022-2028: Research Report on technology, participants, trends, market size and share
WCF更新服务引用报错的原因之一
Constant pointer and pointer constant
常量指针和指针常量
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
It's great to save 10000 pictures of girls
王-课外单词
C语言的库函数
STL速查手册
MySQL优化
Deep understanding of JVM
SQL server如何卸载干净
Library function of C language
install.img制作方式
Look for we media materials from four aspects to ensure your creative inspiration
Graph Pooling 简析
Sqlyog remote connection to MySQL database under centos7 system
Rhel7 operation level introduction and switching operation
Force buckle method summary: sliding window
深入理解JVM