binary digits can be placed
in a circle so that all the -digit
clockwise subsequences are distinct.
For , two such circular
arrangements are possible, ignoring rotations:
For the first arrangement, the -digit subsequences, in clockwise order,
are: and .
Each circular arrangement can be encoded as a number by concatenating
the binary digits starting with the subsequence of all zeros as the most
significant bits and proceeding clockwise. The two arrangements for
are thus represented as and :
Calling the sum of the
unique numeric representations, we can see that . Find .
N = 5 M = 1 << N mask = (1 << N) - 1 g = [[i << 1 & mask, (i << 1 | 1) & mask] for i inrange(M)] vis = [0for i inrange(M)] vis[0] = 1 ans = 0
defdfs(f: int, u: int, s: int): if f == M - 1: if u == (M >> 1): global ans ans += s >> (N - 1) return for v in g[u]: if vis[v]: continue vis[v] = 1 dfs(f + 1, v, s << 1 | (v & 1)) vis[v] = 0