n, m, k = map(int, input().split())
stacks = []
for i in range (n):
s = list(map(int, input().split()))
stacks.append(s)
increasing = []
for i in range (n):
if stacks[i][0] < stacks[i][m-1]:
increasing.append(True)
else:
increasing.append(False)
prefix_sums = []
for i in range(n):
prefix_sums.append([0])
# prefix_sums.append([stacks[i][0]])
for j in range(1, m+1):
prefix_sums[i].append(prefix_sums[i][j-1] + stacks[i][j-1])
def select(i, total_number, total_cost):
if total_number == k:
return total_cost
else:
maxx = 0
for j in range(m+1):
if total_number + j <= k and i < n:
maxx = max(maxx, select(i+1, total_number + j, total_cost + prefix_sums[i][j]))
return maxx
res = select(0, 0, 0)
print(res)
# print(stacks)
# print(increasing)
# print(prefix_sums)
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 32 33 34 35 36 37 38 39 40 41 42 43 44 | n, m, k = map(int, input().split()) stacks = [] for i in range (n): s = list(map(int, input().split())) stacks.append(s) increasing = [] for i in range (n): if stacks[i][0] < stacks[i][m-1]: increasing.append(True) else: increasing.append(False) prefix_sums = [] for i in range(n): prefix_sums.append([0]) # prefix_sums.append([stacks[i][0]]) for j in range(1, m+1): prefix_sums[i].append(prefix_sums[i][j-1] + stacks[i][j-1]) def select(i, total_number, total_cost): if total_number == k: return total_cost else: maxx = 0 for j in range(m+1): if total_number + j <= k and i < n: maxx = max(maxx, select(i+1, total_number + j, total_cost + prefix_sums[i][j])) return maxx res = select(0, 0, 0) print(res) # print(stacks) # print(increasing) # print(prefix_sums) |
English