Primeiro problema!
This commit is contained in:
parent
4e8f66c58d
commit
162943a922
48
Problems/Codeforces/Round_105(U)/CF_148E(O).cpp
Normal file
48
Problems/Codeforces/Round_105(U)/CF_148E(O).cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
|
||||
int n,m, x;
|
||||
vector<vector<int>> shelfs, optansw, prefs, tabulardp;
|
||||
|
||||
cin >> n >> m;
|
||||
shelfs.assign(n, vector<int>());
|
||||
prefs.assign(n, vector<int>());
|
||||
optansw.assign(n, vector<int>(min(m+1, 101), 0));
|
||||
|
||||
for(int i = 0; i < n; i++){
|
||||
cin >> x;
|
||||
shelfs[i].resize(x);
|
||||
prefs[i].resize(x+1); prefs[i][0] = 0;
|
||||
for(int j = 0; j < x; j++){
|
||||
cin >> shelfs[i][j];
|
||||
prefs[i][j+1] = prefs[i][j] + shelfs[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < n; i++){
|
||||
optansw[i][shelfs[i].size()] = prefs[i][shelfs[i].size()];
|
||||
for(int l = 0; l < shelfs[i].size(); l++){
|
||||
for(int r = l; r < shelfs[i].size(); r++){
|
||||
optansw[i][shelfs[i].size() - (r-l+1)] = max(optansw[i][shelfs[i].size() - (r-l+1)], prefs[i][shelfs[i].size()] - prefs[i][r+1] + prefs[i][l]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tabulardp.assign(n+1, vector<int>(m+1, 0));
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){ // Descendo inicialmente j e pegando opt[0]
|
||||
int stop = min((int)optansw[i-1].size()-1, j);
|
||||
for(int k = 0; k <= stop; k++){
|
||||
tabulardp[i][j] = max(tabulardp[i][j], tabulardp[i-1][j-k] + optansw[i-1][k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << tabulardp[n][m] << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
51
Problems/Codeforces/Round_105(U)/CF_148E.cpp
Normal file
51
Problems/Codeforces/Round_105(U)/CF_148E.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(false);
|
||||
|
||||
int n,m, x;
|
||||
vector<vector<int>> shelfs, optansw, prefs, tabulardp;
|
||||
|
||||
cin >> n >> m;
|
||||
shelfs.assign(n, vector<int>());
|
||||
prefs.assign(n, vector<int>());
|
||||
optansw.assign(n, vector<int>(101, 0));
|
||||
|
||||
for(int i = 0; i < n; i++){
|
||||
cin >> x;
|
||||
shelfs[i].resize(x);
|
||||
prefs[i].resize(x+1); prefs[i][0] = 0;
|
||||
for(int j = 0; j < x; j++){
|
||||
cin >> shelfs[i][j];
|
||||
prefs[i][j+1] = prefs[i][j] + shelfs[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < n; i++){
|
||||
optansw[i][shelfs[i].size()] = prefs[i][shelfs[i].size()];
|
||||
for(int l = 0; l < shelfs[i].size(); l++){
|
||||
for(int r = l; r < shelfs[i].size(); r++){
|
||||
optansw[i][shelfs[i].size() - (r-l+1)] = max(optansw[i][shelfs[i].size() - (r-l+1)], prefs[i][shelfs[i].size()] - prefs[i][r+1] + prefs[i][l]);
|
||||
}
|
||||
}
|
||||
for(int l = shelfs[i].size()+1; l < 101; l++){
|
||||
optansw[i][l] = optansw[i][l-1];
|
||||
}
|
||||
}
|
||||
|
||||
tabulardp.assign(n+1, vector<int>(m+1, 0));
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= m; j++){ // Descendo inicialmente j e pegando opt[0]
|
||||
int stop = min(100, j);
|
||||
for(int k = 0; k <= stop; k++){
|
||||
tabulardp[i][j] = max(tabulardp[i][j], tabulardp[i-1][j-k] + optansw[i-1][k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << tabulardp[n][m] << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user