Skip to content

Instantly share code, notes, and snippets.

@nishidy
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishidy/6939c3d13fe2e944ef6f to your computer and use it in GitHub Desktop.
Save nishidy/6939c3d13fe2e944ef6f to your computer and use it in GitHub Desktop.
Round 1C 2015: Problem B. Typewriter Monkey
from math import *
T=int(raw_input())
t=0
while t<T:
K,L,S=map(lambda x:int(x),raw_input().split())
k=raw_input()
l=raw_input()
n=0
for i in range(1,len(l)):
if l[i:L]==l[0:L-i]:
n=L-i
break
m=floor((S-n)/(L-n))
x=1.0
for _l in l:
if k.count(_l)==0:
a=0
break
else:
x*=k.count(_l)
else:
a=m-(S-L+1)*x/(K**L)
t+=1
print "Case #%d: %.7f"%(t,a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment