2027lanjiaye • 1个月前
using namespace std; int n, m,w[1001][1001],dp[1001][1001]; int main() {
while (cin >> n >> m && (n || m)) {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cin >> w[i][j];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = dp[i - 1][j];
for (int k = 1; k <= min(j, m); ++k) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + w[i][k]);
}
}
}
cout << dp[n][m] << endl;
}
return 0;
}
评论: