這次是參加vitual
Q1
檢查兩值的奇偶
Q2
k-size MaxHeap
Q3
因為測資只有1~100, row/col長度最多也才10
所以我是建val dict, 裡面存row的index
然後遞迴加1~100 用bitmask判斷row有沒重複過
加上cache雖然有過 但還是跑了8000+ ms lol
```python
class Solution:
def maxScore(self, grid: List[List[int]]) -> int:
len_r, len_c = len(grid), len(grid[0])
table = defaultdict(list) # val: list[row idx]
for r in range(len_r):
for c in range(len_c):
table[grid[r][c]].append(r)
@cache
def recur(i, mask):
if i == 101:
return 0
if mask == (1 << len_r) - 1:
return 0
res = recur(i+1, mask) # skip
for j in range(i, 101):
for r in table[j]:
if mask & (1 << r):
continue
res = max(res, j + recur(j+1, mask | 1 << r))
return res
return recur(0, 0)
```
Q4
我不會