11022 - String Factoring
Moderator: Board moderators
11022 - String Factoring
Hi,
can anybody give me some tricky examples?
Thanks
can anybody give me some tricky examples?
Thanks
Here are some samples
Input:
Output:
Hope it helps.
Input:
Code: Select all
ABCABCCBACBA
AAAAABBBABBB
BBAXXBBAXX
AABBCCBBAA
ABCDEFGHGHGHEF
FINLALLY
ACCEPTED
*
Code: Select all
6
3
3
5
10
7
7
Ami ekhono shopno dekhi...
HomePage
HomePage
You can solve it by recursion. To make it faster use memorization.
Ami ekhono shopno dekhi...
HomePage
HomePage
Yes, definitelyTimo wrote:it is 90% similiar to matrix chain multiplication problem

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

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*/
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...
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
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
------------------------------------------------------------------------
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
I have no clue about the DP to be used for the problem. Any hints please?