diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/codeforces/round-105/e/E. Porcelain b/codeforces/round-105/e/E. Porcelain deleted file mode 100755 index de7dc4a..0000000 Binary files a/codeforces/round-105/e/E. Porcelain and /dev/null differ diff --git a/codeforces/round-105/e/E. Porcelain.cpp b/codeforces/round-105/e/E. Porcelain.cpp index 004e077..d39ab16 100644 --- a/codeforces/round-105/e/E. Porcelain.cpp +++ b/codeforces/round-105/e/E. Porcelain.cpp @@ -76,24 +76,43 @@ int main() cin >> n >> m; vvl plates(n); + vl maxi(n, 0); + vvl prefix(n); rep(i, n) { int n; cin >> n; plates[i].resize(n); - cin >> plates[i]; + prefix[i].resize(n + 1); + prefix[i][0] = 0; + for (size_t j = 0; j < n; j++) { + cin >> plates[i][j]; + prefix[i][j + 1] = prefix[i][j] + plates[i][j]; + maxi[i] += plates[i][j]; + } } - vvl dp(n, vl(100, 0)); + vvl dp(n, vl(101, 0)); for (size_t i = 0; i < n; i++) { - vvl dp2(101, vl(101, 0)); + dp[i][plates[i].size()] = maxi[i]; + for (size_t j = 0; j < plates[i].size(); j++) { + for (size_t k = j; k < plates[i]. size(); k++) { + rmax(dp[i][plates[i].size() - (k - j + 1)], maxi[i] - prefix[i][k + 1] + prefix[i][j]); + } + } + for (size_t j = plates[i].size() + 1; j <= 100; j++) { + dp[i][j] = dp[i][j - 1]; + } + } + // cout << dp; - for (int k = plates[i].size() - 1; k >= 0; k--) { - for (int j = 1; j <= k; j++) { - dp2[j][k] = max(dp2[j - 1][k] + plates[i][j - 1], dp2[j][k + 1] + plates[i][k]); - rmax(dp[i][plates[i].size()-(k-j)], dp2[j][k]); + vvl ans(n + 1, vl(m + 1, 0)); + for (size_t i = 1; i <= n; i++) { + for (size_t j = 1; j <= m; j++) { + for (size_t k = 0; k <= j && k <= 100; k++) { + rmax(ans[i][j], ans[i - 1][j - k] + dp[i - 1][k]); } } } - cout << dp; + cout << ans[n][m] << '\n'; }