totalLen = sum(matchsticks)
if totalLen % 4:
return False
matchsticks.sort(reverse=True)
edges = [0] * 4
def dfs(idx: int) -> bool:
if idx == len(matchsticks):
return True
for i in range(4):
edges[i] += matchsticks[idx]
if edges[i] <= totalLen // 4 and dfs(idx + 1):
return True
edges[i] -= matchsticks[idx]
return False
return dfs(0)
每日一题,六一儿童节,火柴搭正方形,由此引申到找到数组中k个和相等子集。