bzoj1068: [SCOI2007]压缩

状态定义是(l,r,t)表示l到r的字串,t表示中间能否放M,注意最开始有个M

const int N = 60;
char Dat[N];
int Dp[N][N][2];
bool Vis[N][N][2];

inline void Input() {
	scanf("%s", Dat + 1);
}

inline bool Match(int A, int B) {
	int Len = B - A;
	Rep(i, Len)
		if(Dat[A + i] ^ Dat[B + i]) return 0;
	return 1;
}
inline int Search(int L, int R, bool Able) {
	if(Vis[L][R][Able]) return Dp[L][R][Able];
	if(L == R) return 1;
	Vis[L][R][Able] = 1;
	int Ret = R - L + 1, Len = R - L + 1;
	For(i, L, R - 1) {
		if(Able) Ret = min(Ret, Search(L, i, 1) + 1 + Search(i + 1, R, 1));
		Ret = min(Ret, Search(L, i, Able) + R - i);
	}
	if(Len % 2 == 0 && Match(L, L + (Len >> 1))) Ret = min(Ret, Search(L, L + (Len >> 1) - 1, 0) + 1);
	return Dp[L][R][Able] = Ret;
}
inline void Solve() {
	printf("%d\n", Search(1, strlen(Dat + 1), 1));
}

int main() {
	#ifndef ONLINE_JUDGE
	SETIO("1068");
	#endif
	Input();
	Solve();
	return 0;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值