#第二题,常见的DFS
while True:
try:
M, N = map(int, input().split(','))
data = []
res = 0
for _ in range(M):
lst = list(input())
data.append(lst)
def backtrack(i, j):
if i < 0&nbs***bsp;j < 0&nbs***bsp;i > M - 1&nbs***bsp;j > N - 1&nbs***bsp;data[i][j] == "H":
return
data[i][j] = 'H'
backtrack(i + 1, j)
backtrack(i - 1, j)
backtrack(i, j + 1)
backtrack(i, j - 1)
return
for i in range(M):
for j in range(N):
if data[i][j] == "S":
backtrack(i, j)
res += 1
print(res)
except:
break
#81.82%,第三题,很常见的0-1背包问题
while True:
try:
K = int(input())
N = int(input())
w = list(map(int, input().split()))
v = list(map(int, input().split()))
dp = [0] * (K + 1)
for i in range(1, N + 1):
for j in range(K, 0, - 1):
if j >= w[i - 1]:
dp[j] = max(dp[j], dp[j - w[i - 1]] + v[i - 1])
print(dp[-1])
except:
break
第三题还要满足最大体积,没有思路,各位指点一下
🤣#笔试题目##华为#