11022 - String Factoring
Posted: Sun Apr 02, 2006 2:00 pm
Hi,
can anybody give me some tricky examples?
Thanks
can anybody give me some tricky examples?
Thanks
Code: Select all
ABCABCCBACBA
AAAAABBBABBB
BBAXXBBAXX
AABBCCBBAA
ABCDEFGHGHGHEF
FINLALLY
ACCEPTED
*
Code: Select all
6
3
3
5
10
7
7
Yes, definitelyTimo wrote:it is 90% similiar to matrix chain multiplication problem
Code: Select all
/*Hidden above*/
string t, A, B;
int tind, p;
A = DP[i][j];
B = DP[j+1][m];
if (A == B){
t = A;
tind = ind[i][j] + ind[j+1][m];
p = ans[i][j];
}else{
char Tp;
Tp = ind[i][j];
A=A+'*'+Tp;
Tp = ind[j+1][m];
B=B+'*'+Tp;
t = A+B;
tind = 1;
p = ans[i][j] + ans[j+1][m];
}
if (/*comparison*/){
/*Assign new DP value*/
}
/* Hidden below*/
Yep, under some but limited optimization, I got 0:00.58x.Timo wrote:My solution is use recursive with memo and I get 0:00.051.
I think you must optimize your dp.