Page 1 of 2

10081 - Tight Words

Posted: Thu Jun 20, 2002 4:56 pm
by Chameleon
I have written code for 10081, but the judge doesn't like it.
Any ideas?

Posted: Thu Jun 20, 2002 7:27 pm
by 10153EN
Any more information? e.g. what's the judge's reply?

and what's your algorithm in solving it?

Posted: Thu Jun 20, 2002 7:31 pm
by Chameleon
"Incorrect output".

I was using a recursive way that counted the number of ways to generate the word, and then for efficiency converted to iterative.

Result = Tight words / Total words

where total words = (k+1)^n

I had to put in some tricks to overcome overflow... perhaps that is the problem.

Posted: Fri Jun 21, 2002 4:10 pm
by junjieliang
While counting the number of tight words and total words use double if not I think you could get integer overflow.

10081 - What the problem states and how can I solve it?

Posted: Wed Feb 25, 2004 10:57 am
by Master
Would you pls tell me what the problem states and How can I solve it? :roll:
If you know then Pls tell me....

Thanks in advance
M H Rasel
Cuet Old Sailor

confusing

Posted: Wed Feb 25, 2004 11:54 am
by sohel
This problem is hard to understand if you read it only once, but if you read it 3-4 times then you will probably get the hang of it.

consider the second case in the sample:
2 5

here k is 2 and n is 5.

you can form 3^5 numbers.... ( allowed digits are 0,1,2 and of length 5).

Of these 3^5 numbers, the numbers whose adjacent digits do not differ by one are tight words (numbers).
Just output the percentage.

Hint: Use DP as manual genertions will exceed Mem limit && time limit.

Hope it helps.
:wink:

10081 (Tight Words) - Wrong Answer

Posted: Tue Feb 08, 2005 3:25 pm
by Digit
I'm trying to solve 10081, Tight words, but I'm getting WA all the time.

Can anybody give me the number of tight words for input '9 100' ?

I know that this is not asked, but this is part of the solution.
My program says 1069966138. Is this correct?

Or maybe someone has some input/output for testing?

Thanks.

Posted: Tue Feb 08, 2005 4:36 pm
by Eduard
Here are some tests.
Input

Code: Select all

0 8
5 10
2 20
2 30
2 40
2 50
2 60
2 70
9 13
Output

Code: Select all

100.00000
0.09657
1.56615
0.17839
0.02032
0.00231
0.00026
0.00003
0.00012

10081 - Tight Words

Posted: Tue Aug 02, 2005 2:44 pm
by jagadish
How do u acheive precision for this problem ? I used double and got quite different results for the above case :

Code: Select all

100.00000
0.09657
1.56615
0.17839
0.02032
0.00231
0.00026
0.00003
0.00003
for 9 100 i get 0.00000 ..

Re: How to solve problem 10081?

Posted: Thu Aug 04, 2005 3:28 pm
by chunyi81
I was trying to solve this problem but could not figure out how to use DP here. Here is what I observed: For a string of length i ending with digit j, then the second last digit will be j - 1, j or j + 1 if 1 <= j <= k - 2, 0 or 1 if j = 0, and k - 2 or k - 1 if j = k - 1. At first I thought of using memoization(using a lookup table), after trying to work out the recursion tree to calculate the number of tight words for a small example, say the first test data in the sample input: 2 5. The lookup table would become too big because there are too many places in the recursion tree where the same value is calculated more than once.
Can anyone give me a hint how to use DP for this problem? Thanks.

Re: How to solve problem 10081?

Posted: Thu Aug 04, 2005 8:16 pm
by jagadish
Got AC despite some lossy precision..
chunyi81 wrote: For a string of length i ending with digit j, then the second last digit will be j - 1, j or j + 1 if 1 <= j <= k - 2, 0 or 1 if j = 0, and k - 2 or k - 1 if j = k - 1.
formally that would look like :
f(n,t) = f(n-1,t-1)+f(n-1,t)+f(n-1,t+1)
take advantage of the fact that f(n) needs only f(n-1)

Posted: Fri Aug 05, 2005 9:51 am
by chunyi81
Thanks jagadish for the recurrence equation you posted. I figured out how to solve this problem using DP.

Re: 10081 - Tight Words

Posted: Fri Mar 17, 2006 6:12 am
by migichen
jagadish wrote:How do u acheive precision for this problem ? I used double and got quite different results for the above case :

Code: Select all

100.00000
0.09657
1.56615
0.17839
0.02032
0.00231
0.00026
0.00003
0.00003
for 9 100 i get 0.00000 ..
My program which got AC has the same result :)

Re: 10081 - Tight words

Posted: Thu May 15, 2008 6:41 pm
by Alberto
for k=9 and n=100
the number of tight words:
tights = 100512267936480837475180750161082113997249340218
And the number of possible words:
possibles = (k+1)^n = 10^100
Then
% = 100.0*(tights/possibles)
% = 0.00000

Re: 10081 - Tight words

Posted: Sun Aug 31, 2014 12:40 pm
by Mukit Chowdhury
Astonished to see, for computing 10^100 pow() can be used !!!! Would anybody please tell me, what is the actual range of returned value of pow() in C++ ??? It'll really help.... :)
Thanks in advance... :)