-
-
Save nishidy/6939c3d13fe2e944ef6f to your computer and use it in GitHub Desktop.
Round 1C 2015: Problem B. Typewriter Monkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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