"Bzoj" 1090: [SCOI2003] string folding (DP)

Source: Internet
Author: User

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

Casually yy.

Set F[I,J] Indicates the minimum length of the I~j

F[i, J]=min{j-i+1, F[i,k]+f[k+1, J], Count[x]+2+f[i, I+x-1]}, where count[x] represents the number of bits of x, and the last side of the transition that condition is that i~j are concatenated together in length X.

Then the last transfer of violence 233 can be water over ...

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x) puts ("error"): 0) #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) inline const int Getint () {int r=0, k=1; Char c=g Etchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }const int N=105;char s[n];int f[n][n], C[n];int main () {scanf ("%s", s+1); For1 (I, 1,) if (i<10) c[i]=1; else if (i<100) c[i]=2; else C[i]=3;int N=strlen (s+1); Rep (len, N) for1 (i, 1, n) {int j=i+len;if (j>n) break;int &d=f[i][j], l=j-i+1;d=l;for 1 (k, I, j-1) d=min (d, F[i][k]+f[k+1][j]), For1 (x, 1, L) if (l%x==0) {int Flag=1;for1 (now, I, i+x-1) {int Next=now+x;while (NE XT&LT;=J) {if (S[next]!=s[now]) {flag=0; break;} next+=x;} if (!flag) break;} if (flag) d=min (d, C[l/x]+2+f[i][i+x-1]);}} printf ("%d\n", F[1][n]); return 0;}

  

Description

The definition of folding is as follows: 1. A string can be seen as its own folding. Remember it as s? S 2. X (S) is the folding of the string of X (x>1) s connected together. Remember as X (S)? SSSS ... s (x s). 3. What if a? A ', B? B ', then AB? A ' B ' For example, because 3 (a) = AAA, 2 (B) = BB, so 3 (a) C2 (b)? AAACBB, and 2 (3 (A) C) 2 (B)? AAACAAACBB gives a string to the shortest fold. For example, the shortest folding of the AAAAAAAAAABABABCCD is: 9 (A) 3 (AB) CCD.

Input

Only one line, the string s, guarantees a length of not more than 100.

Output

Only one line, that is, the shortest folding length.

Sample Inputneercyesyesyesneercyesyesyessample Output14hint

One of the shortest folds is: 2 (NEERC3 (YES))

Source

"Bzoj" 1090: [SCOI2003] string folding (DP)

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.