from itertools import chain, combinations
def solve(L):
M = {}
result = 0
for ss in chain.from_iterable(combinations(L, r) for r in range(len(L)+1)):
if ss not in M: M[ss] = 0
M[ss] += 1
for (_, count) in M.items():
if count > 1:
result += 1
return result
def brut(L, Q):
L = list(L)
print(solve(L))
for (p, z) in Q:
L[p-1] = z
print(solve(L))
if __name__ == "__main__":
[n, q] = list(map(int, input().strip().split(' ')))
L = list(input().strip())
Q = []
for i in range(q):
[p, z] = list(input().strip().split(' '))
p = int(p)
Q.append((p, z))
brut(L, Q)
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 | from itertools import chain, combinations def solve(L): M = {} result = 0 for ss in chain.from_iterable(combinations(L, r) for r in range(len(L)+1)): if ss not in M: M[ss] = 0 M[ss] += 1 for (_, count) in M.items(): if count > 1: result += 1 return result def brut(L, Q): L = list(L) print(solve(L)) for (p, z) in Q: L[p-1] = z print(solve(L)) if __name__ == "__main__": [n, q] = list(map(int, input().strip().split(' '))) L = list(input().strip()) Q = [] for i in range(q): [p, z] = list(input().strip().split(' ')) p = int(p) Q.append((p, z)) brut(L, Q) |
English