从序列中每次消去回文串,问最少几次消除完
#include <iostream> #include <cstring> using namespace std ; const int N=503,inf=0x3f3f3f3f; int f[N][N],a[N],n; signed main(){ int i,j,k,l,X; memset(f,inf,sizeof f); cin>>n; for(i=1;i<=n;i++) cin>>a[i],f[i][i]=1; for(i=1;i<n;i++) if(a[i]==a[i+1]) f[i][i+1]=1; else f[i][i+1]=2; for(l=3;l<=n;l++) for(i=1;i+l-1<=n;i++){ j=i+l-1; if(a[i]==a[j]) f[i][j]=f[i+1][j-1]; for(k=i;k<j;k++){ f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]); } } cout<<f[1][n]; }
标签:int,memset,zuma,CF607B,inf,include From: https://www.cnblogs.com/towboa/p/17153278.html