fork download
  1. def matmul(a,b,l,m,n):
  2. c = []
  3. for i in range(l):
  4. dummy = []
  5. for j in range(n):
  6. ans = 0
  7. for k in range(m):
  8. ans = ans + a[i][k] * b[k][j]
  9. dummy.append(ans)
  10. c.append(dummy)
  11. return c
  12.  
  13. def power_matrix(a,n):
  14. if n == 0:
  15. return 1
  16. elif n == 1:
  17. return a
  18. elif n%2 == 0:
  19. return power_matrix(matmul(a,a,26,26,26),n/2)
  20. elif n%2 == 1:
  21. return matmul(a,power_matrix(matmul(a,a,26,26,26),(n-1)/2))
  22.  
  23.  
  24. a = []
  25. for i in range(26):
  26. k = []
  27. for j in range(26):
  28. k.append(0.0)
  29. a.append(k)
  30. t = input()
  31. for dummy in range(t):
  32. n, k = raw_input().split()
  33. n = int(n)
  34. k = int(k)
  35.  
  36. sum_of_Prob = 0
  37.  
  38. word = raw_input()
  39. length = len(word)
  40. word = list(word)
  41. for i in range(length):
  42. word[i] = ord(word[i]) - 97
  43.  
  44. for i in range(26):
  45. num = raw_input().split()
  46. for j in range(26):
  47. a[i][j] = float(num[j])
  48.  
  49. a = power_matrix(a,k)
  50. prob = 0
  51. for j in range(n):
  52. p1 = 1
  53. str1 = raw_input()
  54. if(len(str1) != length):
  55. continue
  56. else:
  57. s = list(str1)
  58. for i in range(len(s)):
  59. s[i] = ord(s[i])-97
  60. for i in range(length):
  61. p1 = p1*a[word[i]][s[i]]
  62. if p1 == 0:
  63. break
  64. prob = prob + p1
  65. print prob
Runtime error #stdin #stdout #stderr 0.01s 7852KB
stdin
1
2 3
a
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0.5 0 0.5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0.1 0.9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 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0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ab
b
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 49, in <module>
  File "prog.py", line 21, in power_matrix
TypeError: matmul() takes exactly 5 arguments (2 given)