# bzoj1032[JSOI2007]祖码Zuma

http://www.lydsy.com/JudgeOnline/problem.php?id=1032

https://www.luogu.org/discuss/show?postid=8416

#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

#define N 501

int a[N];

int col[N],num[N];

int f[N][N];

{
x=0; int f=1; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-1;  c=getchar();}
while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
x*=f;
}

int main()
{
int n;
int cnt=0;
for(int i=1;i<=n;++i)
{
if(a[i]!=a[i-1] || i==1)
{
col[++cnt]=a[i];
num[cnt]=1;
}
else num[cnt]++;
}
memset(f,63,sizeof(f));
for(int i=1;i<=cnt;++i)
{
if(num[i]==1) f[i][i]=2;
else f[i][i]=1;
}
int j;
for(int len=2;len<=cnt;++len)
{
for(int i=1;i+len-1<=cnt;++i)
{
j=i+len-1;
if(col[i]==col[j])
{
if(num[i]+num[j]==2) f[i][j]=f[i+1][j-1]+1;
else f[i][j]=f[i+1][j-1];
}
for(int k=i;k<j;++k) f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]);
}
}
cout<<f[1][cnt];
}

## 1032: [JSOI2007]祖码Zuma

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1181  Solved: 616
[Submit][Status][Discuss]

## Sample Input

9
1 1 2 2 3 3 2 1 1

## Sample Output

1
posted @ 2017-11-26 14:31  TRTTG  阅读(347)  评论(0编辑  收藏  举报