-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
31 lines (26 loc) · 763 Bytes
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#https://www.acmicpc.net/problem/18290
from itertools import combinations
N,M,K=map(int,input().split())
board=[list(map(int,input().split())) for _ in range(N)]
idxs=[(r,c) for r in range(N) for c in range(M)]
def isclose(comb):
for i,j in combinations(comb,2):
r,c=i
if j==(r-1,c) or j==(r+1, c) or j==(r, c-1)or j==(r, c+1):
return True
return False
ans=-60000
for comb in combinations(idxs,K):
if not isclose(comb):
tempans=0
for r,c in comb:
tempans+=board[r][c]
ans=max(tempans,ans)
print(ans)
# def backt(r,c,depth):
# global ans
# if depth==K:
# ans=max(sum(select),ans)
# return
# for i in range(N):
# for j in range(c,M+1):