[CQOI2007] [BZOJ1260] Coloring Paint

Source: Internet
Author: User
Tags uppercase letter

1260: [CQOI2007] Paint paint time limit:30 Sec Memory limit:64 MB
submit:814 solved:492
[Submit] [Status] [Discuss] Description assume that you have a 5-length block that has not been painted in any color at the beginning. You want to apply its 5 unit lengths to red, green, blue, green, and red, using a string of length 5 to indicate this target: RGBGR. Each time you can paint a continuous piece of wood into a given color, the color of the coat is covered with the first color. For example, for the first time, the wood planks were painted rrrrr, the second painted Rgggr, the third painted rgbgr, to achieve the goal. Achieve your goals with as few coloring times as possible. Input enters only one row, containing a string of length n, which is the coloring target. Each character in a string is an uppercase letter, different letters represent different colors, and the same letters represent the same color. Output has only one row, which contains a single number, which is the minimum number of paint times. Sample Input Sample Output"Sample Input 1"
AAAAA

"Sample Input 1"
Rgbgr

"Sample Output 1"
1

"Sample Output 1"
3


HINT

40% of the data meet: 1<=n<=10
100% of the data meet: 1<=n<=50

Source

You can make f[i][j] represent the minimum number of times the i->j is applied. Initial f[i][j]=+∞,f[i][i]=1.

If i=j, then F[i][j]=min (f[i+1][j],f[i][j-1],f[i+1][j-1]+1). I!=j f[i][j]=min (F[i][k]+f[k+1][j])

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cstdlib>#include<cmath>#include<vector>using namespacestd;Chars[ -];intlen,j,f[ -][ -];intMain () {scanf ("%s", s+1); Len=strlen (s+1); Memset (F,127,sizeof(f));  for(intI=1; i<=len;i++) f[i][i]=1;  for(intL=1; l<len;l++)         for(intI=1; i<len;i++) {J=i+l; if(J>len) Break; if(s[i]==S[j]) {F[i][j]=min (f[i+1][j],f[i][j-1]); F[I][J]=min (f[i][j],f[i+1][j-1]+1); }            Else  for(intk=i;k<j;k++) F[i][j]=min (f[i][j],f[i][k]+f[k+1][j]); } printf ("%d", f[1][len]); return 0;}

[CQOI2007] [BZOJ1260] Coloring Paint

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.