提交时间:2024-04-06 17:35:00

运行 ID: 142237

#include<iostream> #include<vector> using namespace std; const int N = 1e2 + 10; int n, m, t, f[N][N*N], w[N][N], maxn = 0; vector<int> group[N]; int main(){ while(cin >> n >> m && !(m == 0 && n == 0)){ for(int i = 0; i < N; i++){ while(group[i].size()) group[i].pop_back(); for(int j = 0; j < N*N; j++) f[i][j] = 0; } 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++){ f[i][j] = f[i-1][j]; for(int k = 1; k <= n; k++){ if(j - k >= 0){ f[i][j] = max(f[i][j], f[i-1][j-k] + w[i][k]); } maxn = max(maxn, f[i][j]); } } } cout << maxn << endl; } return 0; }