为什么第二个点会 WA 啊?
  • 板块P1357 花园
  • 楼主iwoeix
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/7/25 14:20
  • 上次更新2023/11/3 07:45:02
查看原帖
为什么第二个点会 WA 啊?
1006291
iwoeix楼主2023/7/25 14:20

rt,我觉得这么写不会溢出啊……

import numpy as np

def popcount(x): return bin(x).count('1')
P = int(1e9 + 7)
class matrix:
    def __init__(self, x): self.x = x
    def __matmul__(self, other): return matrix(np.array([[np.sum(self.x[i] @ other.x[:, j] % P) % P for j in range(other.x.shape[1])] for i in range(self.x.shape[0])]))

n, m, k = map(int, input().split())
b = matrix(np.zeros((1 << m, 1 << m), dtype=np.int64))

for i in range(1 << m):
    if popcount(i) > k: continue
    b.x[i >> 1][i] = 1
    j = (i >> 1) | (1 << (m - 1))
    if popcount(j) <= k:
        b.x[j][i] = 1

res = matrix(np.identity(1 << m, np.int64))
while n:
    if n & 1: res = res @ b
    b = b @ b
    n >>= 1

print(res.x.trace() % P)
2023/7/25 14:20
加载中...