题目描述
blablabla
样例
blablabla
算法1
DP
没法AC,记录下代码
时间复杂度
参考文献
Python 代码
from sys import stdin
N = 12
M = 1 << N
f = [[0 for _ in range(M)] for _ in range(N)]
st = [False]*M
if __name__ == "__main__":
n, m = map(int, input().split())
while n or m:
for i in range(len(f)):
for j in range(len(f[0])):
f[i][j] = 0
for i in range(len(st)):
st[i] = False
for i in range(0, 1<<n):
st[i] = True
cnt = 0
for j in range(0, n):
if i >> j & 1:
if cnt & 1 :st[i] = False
cnt = 0
else: cnt+=1
if cnt & 1: st[i] = False
#n, m = map(int, input().split())
f[0][0] = 1
for i in range(1, m+1):
for j in range(1<<n):
for k in range(1<<n):
if j&k == 0 and st[j | k]:
f[i][j] += f[i-1][k]
print(f[m][0])
n, m = map(int, input().split())
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
python 写的好像会超时啊。你也是这样么
嗯嗯,是的。会超时。