转Python代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int n,m,k;scanf("%d%d%d",&n,&m,&k); int s[10];for(auto&i:s)scanf("%d",&i); int dp[51][51][51],x;memset(dp,0,sizeof dp); for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) { scanf("%1d",&x);//%1d 读入接下来的仅仅一个数字 for(int l=0;l<=k;l++) dp[i][j][l]=max(dp[i-1][j][l],dp[i][j-1][l]); for(int l=k;l>=x;l--)dp[i][j][l]=max(dp[i][j][l],dp[i][j][l-x]+s[x]); } int ans=0;for(int i=0;i<=k;i++)ans=max(ans,dp[n][m][i]); printf("%d",ans); return 0; }
时间: 2023-11-26 21:06:05 浏览: 68
c++中的<cstdio>实现
以下是转换后的Python代码:
```python
n, m, k = map(int, input().split())
s = [int(x) for x in input().split()]
dp = [[[0 for _ in range(k+1)] for _ in range(m+1)] for _ in range(n+1)]
for i in range(1, n+1):
for j in range(1, m+1):
x = int(input())
for l in range(k+1):
dp[i][j][l] = max(dp[i-1][j][l], dp[i][j-1][l])
for l in range(k, x-1, -1):
dp[i][j][l] = max(dp[i][j][l], dp[i][j][l-x]+s[x])
ans = max(dp[n][m])
print(ans)
```
阅读全文