提交时间:2024-04-06 17:41:01

运行 ID: 142242

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