P4170 [CQOI2007] 涂色
2024年3月29日
code
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
string a,s;
int f[52][52];
int main() {
int n;
cin>>a;
n=a.size();
s=" ";
for(int i=1;i<=n;i++){
s+=a[i-1];
}
// scanf("%s",s+1);
// n=strlen(s+1);
// cout<<n<<"\n";
memset(f,0x7f,sizeof(f));
for(int i=1;i<=n;++i)f[i][i]=1;
for(int l=1;l<n;l++){
for(int i=1,j=1+l;j<=n;i++,j++){
// int j=i+l-1;
if(s[i]==s[j])f[i][j]=min(f[i+1][j],f[i][j-1]);
else{
for(int k=i;k<j;k++){
f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
}
}
}
}
cout<<f[1][n];
return 0;
}

继续阅读
所有文章
2024年3月29日

P1929阶梯之谜

©Mooncyan 2024