Bzoj 1068: [SCOI2007] Compression

Source: Internet
Author: User

You can do this first before you do it http://www.lydsy.com/JudgeOnline/problem.php?id=1090

I was going to do an interval DP.

However too weak to quickly understand how to use the traditional interval DP (interval merge) to write this problem

So first with their yy method of comparison of water to do it again (in fact, the simulation of the test instructions in the compression operation)

Using f[i][j] means that the original string is now processed with the first bit and the minimum cost of the buffer string length J

So F[i][j] can be transferred from these three situations.

F[i-1][j-1]+1 (fill in the original letter)

F[i-j/2][j/2]+1 (fill r,j for even)

F[i][k]+1 (fill m,j=0)

So you can go through the water first (note that a relatively coarse upper bound of J is i*2)

#include <bits/stdc++.h>using namespacestd;Chars[ -];intf[ -][ the];intN,ans;BOOLCheckintLintR) {    intlen=r-l+1;  for(inti=l;i<=r;++i)if(s[i]!=s[i-Len]) return 0; return 1;}intMain () {memset (F,0x3f,sizeof(f)); scanf ("%s", &s[1]); N=strlen (&s[1]); f[0][0]=0;  for(intI=1; i<=n;++i) { for(intJ=max ((I-1)*2,1); j;--j) {F[i][j]=f[i-1][j-1]+1; if((j&1)==0&&check (i-j/2+1, i)) F[I][J]=min (f[i][j],f[i-j/2][j/2]+1); f[i][0]=min (f[i][0],f[i][j]+1); }} ans=f[n][0];  for(inti=n*2; i;--i) ans=min (ans,f[n][i]); printf ("%d\n", ans); return 0;}

Dig this hole first, and then we'll use the traditional interval DP method to pits

Bzoj 1068: [SCOI2007] Compression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.