淘天 1014 笔试
1, 2 纯水题。
- 判断问号做加法
[n, m] = map(int, input().split())
b = []
k = 0
for i in range(n):
s = input()
for elem in s:
if elem == '?':
k += 1
b.append(s)
matrixs = [0, 0, 0, 0, 0]
for i in range(n - 1):
for j in range(m - 1):
tt = 0
t = [b[i][j], b[i + 1][j], b[i][j + 1], b[i + 1][j + 1]]
for elem in t:
if elem == '?':
tt += 1
elif elem == 'W':
tt = -1
break
if tt != -1:
matrixs[tt] += 1
p = (10 ** 9) + 7
def mod_add(a, b):
return ((a % p) + (b % p)) % p
def mod_mut(a, b):
return (a * b) % p
memo = {}
def mod_2p(n):
if n < 0:
return 0
if n == 0:
return 1
if n == 1:
return 2
if n in memo:
return memo[n]
t = mod_2p(n // 2)
result = mod_mut(t, t)
if n % 2 == 1:
result = mod_mut(2, result)
memo[n] = result
return result
f = 0
for i in range(5):
f = mod_add(f, mod_mut(matrixs[i], mod_2p(k - i)))
print(f)
#笔试题解##淘天笔试#