1090: [SCOI2003] String folding
Time Limit:1 Sec
Memory limit:256 MB
Topic Connection http://www.lydsy.com/JudgeOnline/problem.php?id=1090
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 Input
Neercyesyesyesneercyesyesyes
Sample Output
14HINT
Test instructions
Exercises
Hey yo, this problem is exactly the same as http://www.cnblogs.com/qscqesze/p/4782156.html.
Double experience!
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 110000#defineMoD 10007#defineEPS 1e-9#definePi 3.1415926intNum;//const int INF=0X7FFFFFFF; //§ß§é§à§é¨f§³Constll inf=0x3f3f3f3f3f3f3f3fll;inline ll Read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************strings[ the][ the];intN;intdp[ the][ the];intvis[ the][ the];Chars[ the];intFF (intx) { intAdd=0; while(x) {add++; X/=Ten; } returnadd;}stringFintx) { stringSS; while(x) {SS+=(Char) (%Ten+'0'); X/=Ten; } reverse (Ss.begin (), Ss.end ()); returnSS;}intSolveintLintR) { if(Vis[l][r])returnDp[l][r]; VIS[L][R]=1; for(inti=l;i<r;i++) { if(Dp[l][r]>solve (L,i) +solve (i+1, R)) {Dp[l][r]=dp[l][i]+dp[i+1][r]; S[L][R]=s[l][i]+s[i+1][r]; } } for(intI=1; i<r-l+1; i++) { if((r-l+1)% (i)! =0) Continue; intAdd =0; for(intk=0;; k++) { if((k +1) *i>r-l+1) Break; for(intj=0; j<i;j++) { if(s[l+k*i+j]!=s[l+J]) Break; if(j==i-1) Add+=1; } } if(add== (r-l+1)/i) {intPoint=solve (l,l+i-1)+2+FF (add); if(dp[l][r]>Point ) {Dp[l][r]=Point ; S[L][R]=""; S[L][R]+=f (ADD) +'('; S[L][R]+=s[l][(1) *i-1+L]; S[L][R]+=')'; } } } returndp[l][r];}intMain () {scanf ("%s", s+1); N= strlen (s+1); for(intI=1; i<=n;i++) { for(intj=i;j<=n;j++) {Dp[i][j]=j-i+1; for(intk=0; k<j-i+1; k++) {S[i][j]+=s[i+K]; }}} solve (1, N); cout<<dp[1][n]<<Endl; return 0;}
Bzoj 1090: [SCOI2003] string folding interval DP