Page 1 of 1

11022 - String Factoring

Posted: Sun Apr 02, 2006 2:00 pm
by rajkon
Hi,

can anybody give me some tricky examples?

Thanks

Posted: Mon Apr 03, 2006 12:42 am
by Jan
Here are some samples

Input:

Code: Select all

ABCABCCBACBA
AAAAABBBABBB
BBAXXBBAXX
AABBCCBBAA
ABCDEFGHGHGHEF
FINLALLY
ACCEPTED
*
Output:

Code: Select all

6
3
3
5
10
7
7
Hope it helps.

Posted: Sat Apr 15, 2006 7:52 am
by lonelyone
any hint, please

Posted: Sat Apr 15, 2006 8:47 am
by sclo
solve it with dp, it can be done in O(n^3)

Posted: Sat Apr 15, 2006 11:55 am
by Jan
You can solve it by recursion. To make it faster use memorization.

Posted: Mon Apr 17, 2006 8:24 am
by lonelyone
thanks for sclo and jan, I solved it already
it seems as matrix multiply

Lonely

Posted: Tue May 23, 2006 8:37 pm
by devmax
How to use DP?
i think, it is not similar to matrix chain multiplication.

Posted: Wed May 24, 2006 7:46 am
by Timo
it is 90% similiar to matrix chain multiplication problem

:D

Posted: Wed May 24, 2006 10:53 am
by Hackson
Timo wrote:it is 90% similiar to matrix chain multiplication problem

:D
Yes, definitely :D

I 've got this problem accepted, but I think the runtime was a bit too slow. I 've tried writting it in both C++ and pascal, but well, the runtime is about 1.4~1.7sec, which is not enough to solve it for N = 380 (N=80 originally).

I saw most can got it in 0.0xx sec :o

As I am not spoiling , may be I can post part of my code, it's 90% similar to MCM

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*/
where DP stores the factorized string so as to compare, ind stores the index of the factorized string and ans stores the mimimum length.
Is it too slow to solve the problem? And, should DP and ind be used in the solution?

Posted: Wed May 24, 2006 2:30 pm
by Timo
My solution is use recursive with memo and I get 0:00.051.
I think you must optimize your dp.

:D

Posted: Wed May 24, 2006 6:24 pm
by Hackson
Timo wrote:My solution is use recursive with memo and I get 0:00.051.
I think you must optimize your dp.

:D
Yep, under some but limited optimization, I got 0:00.58x.

But I 'd like to ask what you 've memoized?
Is the recursive formula same as mine?

Posted: Sat Jul 01, 2006 6:51 pm
by asif_rahman0
Can someone tell me how can i reduce my Time Limit?
I got it accepted within 0.00.5sec:(.
I used O(n^2) to find Periodic String in MCM. Is there any better algorithm or STL function which can help me to reduce my TL?



thnx
rabbi



------------------------------------------------------------------------

Re: 11022 - String Factoring

Posted: Fri Apr 10, 2009 5:57 pm
by gauravc
I have no clue about the DP to be used for the problem. Any hints please?