from fractions import * line = input() line = line.split() n = int(line[0]) m = int(line[1]) board = [] for i in range(n): row = '.' line = input() row += line row += '.' board.append(row) if n == 1: prefq = [] prefd = [] cntq = 0 cntd = 0 for c in board[0]: if c == '?': cntq += 1 if c == '.': cntd += 1 prefq.append(cntq) prefd.append(cntd) res = Fraction() for i in range(m+1): for j in range(i+1, m+1): if j-i == 2: continue if board[0][i] == 'O' or board[0][j+1] == 'O': continue if prefd[j] > prefd[i]: continue tmp = Fraction(1, 2 ** (prefq[j]-prefq[i])) if board[0][i] == '?': tmp *= Fraction(1, 2) if board[0][j+1] == '?': tmp *= Fraction(1, 2) res += tmp #print(i, j, tmp) print(str(res.numerator) + '/' + str(res.denominator))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | from fractions import * line = input() line = line.split() n = int(line[0]) m = int(line[1]) board = [] for i in range(n): row = '.' line = input() row += line row += '.' board.append(row) if n == 1: prefq = [] prefd = [] cntq = 0 cntd = 0 for c in board[0]: if c == '?': cntq += 1 if c == '.': cntd += 1 prefq.append(cntq) prefd.append(cntd) res = Fraction() for i in range(m+1): for j in range(i+1, m+1): if j-i == 2: continue if board[0][i] == 'O' or board[0][j+1] == 'O': continue if prefd[j] > prefd[i]: continue tmp = Fraction(1, 2 ** (prefq[j]-prefq[i])) if board[0][i] == '?': tmp *= Fraction(1, 2) if board[0][j+1] == '?': tmp *= Fraction(1, 2) res += tmp #print(i, j, tmp) print(str(res.numerator) + '/' + str(res.denominator)) |