提交时间:2024-04-06 14:25:06
运行 ID: 141876
#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline int fr(){ register int x = 0,f = 1; static char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x == 0){ putchar('0'); return ; } if (x < 0){ putchar('-'); x = -x; } stack <char> s; while (x){ s.push(x % 10 + 48); x /= 10; } while (!s.empty()){ putchar(s.top()); s.pop(); } } } using namespace Fast; int w[105][105],dp[105][105]; signed main(){ int n,m; while (cin>>n>>m){ if (n == 0 && m == 0){ break; } for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++){ cin>>w[i][j]; } } memset(dp,0,sizeof(dp)); for (int i = 1;i <= n;i++){ for (int j = 0;j <= m;j++){ for (int k = 0;k <= j;k++){ dp[i][j] = max(dp[i][j],dp[i - 1][j - k] + w[i][k]); } } } cout<<dp[n][m]<<'\n'; } return 0; }