10617 - Again Palindrome

All about problems in Volume 106. 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
Dreamer#1
Learning poster
Posts: 77
Joined: Tue Oct 07, 2003 10:07 pm

10617 - Again Palindrome

Post by Dreamer#1 »

Any hints on how this problem has to be solved? :roll:

It has to be a mathematical solution, can't find it. :(

Hope someone will help. :)
Not all of our dreams can be made to come true. But still we live with the hope to turn them into reality someday.
subbu
New poster
Posts: 28
Joined: Fri May 30, 2003 12:47 am

Post by subbu »

Count the number of palindromes that can be made out of
subsets of the characters of the
given string,
maintaining the order(no permutations allowed).
(same characters at different positions are considered different).

For every palindrome u find in the above way,
there is a unique way of scoring out the letters.


Hope this helps.
Subbu.
HidWalker
New poster
Posts: 3
Joined: Wed May 05, 2004 9:04 am

10617

Post by HidWalker »

I first try to use brute force to solve this problem,
but I got TLE...
I thick there's a better algo, but I still can't find out,
Can someone give me a tip,
What algo should be used here??
Thx.
Eduard
Experienced poster
Posts: 183
Joined: Fri Sep 26, 2003 2:54 pm
Location: Armenia,Yerevan

Post by Eduard »

I solve this problem using DP(Dinamic Programming).

Eduard.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
muvee
New poster
Posts: 25
Joined: Sun Sep 05, 2004 12:41 am

10617.'Again Palindrome'.Output needed for following input

Post by muvee »

Hello guys.

If any of the 'Accepted' guys could give me their output for :
13
AMERFAZALRAHMAN
MIRANDA
GTAVICECITY
GRANDTHEFTAUTO
INTRODUCTIONTOALGORITHMSTHOMASCORMENCHARLESRONALDCLIFFORD
LOWPRICEEDITION
THECLASSICWORK
T
MSNMESSENGER
AAAAAAAA
AAAA
AAABBB
BBBAAA
174
10
35
40
637196
61
22
1
50
255
15
14
14
Many Thanks :)
muvee
New poster
Posts: 25
Joined: Sun Sep 05, 2004 12:41 am

Post by muvee »

No need now guys .. I found my mistake seconds after posting this.

For anybody who attempts this question in the future, you need to use long long !!
Niaz
Learning poster
Posts: 77
Joined: Fri Dec 17, 2004 11:06 am
Location: East West University, Dhaka, Bangladesh
Contact:

Post by Niaz »

I do also understand the problem. But feeling uneasy to solve ! From another thread, I came to know that this problem can be solved by using DP. But I am really very weak in DP. Is there any one who can tell me the procedure of solving this problem using DP ? Is it an Edit Distance problem ?
Waiting for the help.... :-(
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/
d91-lek
New poster
Posts: 22
Joined: Thu Sep 16, 2004 2:25 am
Location: KTH, Stockholm

Post by d91-lek »

f(BAOBAB) = 1 + f(AOBA) + f(BAOBA) + f(AOBAB) - f(AOBA)

The first and last character are either the same or not. Above they are the same and form 1 + f(AOBA) palindromes plus the ones where only one or the other of them is member minus the interval counted twice.

Memoization, keeping a lookup table of function values, is always a soon implemented alternative to Dynamic Programming if you have the simple recursive function written down.
Last edited by d91-lek on Fri May 12, 2006 7:38 pm, edited 1 time in total.
serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

Post by serur »

Also if you use Pascal comp type becomes a must(int64), and therefore also you should write output function manually(at least I did so..),for comp can't be written with writeln(? am I right?)
If there is ever a war between men and machines, it is easy to guess who will start it (c) Arthur Clarke
d91-lek
New poster
Posts: 22
Joined: Thu Sep 16, 2004 2:25 am
Location: KTH, Stockholm

Post by d91-lek »

Good point. Usual integer is not big enough. I didn't think of this at first and then worried I had to use my bignum routines. It was close but C can manage.

Biggest test case

Code: Select all

1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Answer

Code: Select all

1152921504606846975
8 bytes are needed to store 2^60 palindromes. This datatype is commonly called long long int or quad, 4 original 16 bit ints also called words,

To declare and print in C:

Code: Select all

long long int i;
printf("%lld", i);
Pascal I have not tested but on this page http://gnu-pascal.de/gpc/Main-Branch-Integer-Types.html it says GNU Pascal calls this 64 bit datatype LongInt so I presume Writeln can handle it. I hope I have not made you sad, serur, it is never unnecessary to build your own bignum code.
ar2rd
New poster
Posts: 16
Joined: Sat Oct 22, 2005 2:05 am

10617 : Again Palindromes

Post by ar2rd »

Can someone explain me how is the answer for ABA 5?
I counted 4 :
1. leave as it is
2. remove B
3. remove A and A
4. remove everything
You're never too old to become younger...
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Dont open a new thread if there is one already. Use an existing thread.

What if you remove A and B?
Ami ekhono shopno dekhi...
HomePage
pdwd
New poster
Posts: 19
Joined: Sat May 15, 2010 4:35 pm

Re: 10617 - Again Palindromes

Post by pdwd »

Some hints for this problem:

- I used 3 spaces of subproblems;
- Complexity of my algorithm is O(n^2) where n is the length of the word;

Hope it helps, by complexity you can try to guess one space and then find the dependencies.
Post Reply

Return to “Volume 106 (10600-10699)”