11022 - String Factoring

All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
rajkon
New poster
Posts: 5
Joined: Sun Apr 02, 2006 11:59 am

11022 - String Factoring

Post by rajkon »

Hi,

can anybody give me some tricky examples?

Thanks
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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.
Ami ekhono shopno dekhi...
HomePage
lonelyone
Learning poster
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Post by lonelyone »

any hint, please
sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

solve it with dp, it can be done in O(n^3)
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

You can solve it by recursion. To make it faster use memorization.
Ami ekhono shopno dekhi...
HomePage
lonelyone
Learning poster
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Post by lonelyone »

thanks for sclo and jan, I solved it already
it seems as matrix multiply

Lonely
devmax
New poster
Posts: 1
Joined: Tue May 23, 2006 8:08 pm

Post by devmax »

How to use DP?
i think, it is not similar to matrix chain multiplication.
Timo
Learning poster
Posts: 70
Joined: Tue Oct 11, 2005 2:44 am
Location: Indonesia

Post by Timo »

it is 90% similiar to matrix chain multiplication problem

:D
"Life is more beautiful with algorithm"
Hackson
New poster
Posts: 35
Joined: Sun Nov 10, 2002 5:36 am

Post 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?
Solving problem is a no easy task...
Timo
Learning poster
Posts: 70
Joined: Tue Oct 11, 2005 2:44 am
Location: Indonesia

Post by Timo »

My solution is use recursive with memo and I get 0:00.051.
I think you must optimize your dp.

:D
"Life is more beautiful with algorithm"
Hackson
New poster
Posts: 35
Joined: Sun Nov 10, 2002 5:36 am

Post 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?
Solving problem is a no easy task...
asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post 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



------------------------------------------------------------------------
gauravc
New poster
Posts: 2
Joined: Thu Apr 02, 2009 12:11 am

Re: 11022 - String Factoring

Post by gauravc »

I have no clue about the DP to be used for the problem. Any hints please?
Post Reply

Return to “Volume 110 (11000-11099)”