From 162943a922c68bf0067d9262fd626336b167344f Mon Sep 17 00:00:00 2001 From: Daneck1988 Date: Fri, 20 Sep 2024 17:45:58 -0300 Subject: [PATCH] Primeiro problema! --- Contests/void | 0 .../Codeforces/Round_105(U)/CF_148E(O).cpp | 48 +++++++++++++++++ Problems/Codeforces/Round_105(U)/CF_148E.cpp | 51 +++++++++++++++++++ Problems/void | 0 4 files changed, 99 insertions(+) delete mode 100644 Contests/void create mode 100644 Problems/Codeforces/Round_105(U)/CF_148E(O).cpp create mode 100644 Problems/Codeforces/Round_105(U)/CF_148E.cpp delete mode 100644 Problems/void diff --git a/Contests/void b/Contests/void deleted file mode 100644 index e69de29..0000000 diff --git a/Problems/Codeforces/Round_105(U)/CF_148E(O).cpp b/Problems/Codeforces/Round_105(U)/CF_148E(O).cpp new file mode 100644 index 0000000..87bf00e --- /dev/null +++ b/Problems/Codeforces/Round_105(U)/CF_148E(O).cpp @@ -0,0 +1,48 @@ +#include + +using namespace std; + +int main(){ + ios::sync_with_stdio(false); + + int n,m, x; + vector> shelfs, optansw, prefs, tabulardp; + + cin >> n >> m; + shelfs.assign(n, vector()); + prefs.assign(n, vector()); + optansw.assign(n, vector(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(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; +} \ No newline at end of file diff --git a/Problems/Codeforces/Round_105(U)/CF_148E.cpp b/Problems/Codeforces/Round_105(U)/CF_148E.cpp new file mode 100644 index 0000000..af1b599 --- /dev/null +++ b/Problems/Codeforces/Round_105(U)/CF_148E.cpp @@ -0,0 +1,51 @@ +#include + +using namespace std; + +int main(){ + ios::sync_with_stdio(false); + + int n,m, x; + vector> shelfs, optansw, prefs, tabulardp; + + cin >> n >> m; + shelfs.assign(n, vector()); + prefs.assign(n, vector()); + optansw.assign(n, vector(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(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; +} \ No newline at end of file diff --git a/Problems/void b/Problems/void deleted file mode 100644 index e69de29..0000000