feat(DP): new problem formated

This commit is contained in:
2025-11-06 20:04:52 -03:00
parent c916bf6ae5
commit 8db9d73aab
228 changed files with 6879 additions and 0 deletions

30
estouro/src/ac.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> balloons(N);
for (int i = 0; i < N; i++)
cin >> balloons[i];
int n = balloons.size();
balloons.insert(balloons.begin(), 1);
balloons.push_back(1);
vector<vector<int>> dp(balloons.size(), vector<int>(balloons.size(), 0));
for (int len = 1; len <= n; ++len)
{
for (int left = 1; left <= n - len + 1; ++left)
{
int right = left + len - 1;
for (int k = left; k <= right; ++k)
dp[left][right] = max(dp[left][right], balloons[left - 1] * balloons[k] * balloons[right + 1] + dp[left][k - 1] + dp[k + 1][right]);
}
}
cout << dp[1][n] << endl;
return 0;
}

19
estouro/src/checker.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
setName("compare two signed int%d's", 8 * int(sizeof(int)));
registerTestlibCmd(argc, argv);
int ja = ans.readInt();
int pa = ouf.readInt();
if (ja != pa)
quitf(_wa, "expected %d, found %d", ja, pa);
quitf(_ok, "answer is %d", ja);
}

108
estouro/src/generator.cpp Normal file
View File

@@ -0,0 +1,108 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
const int MIN_N = 1;
const int MAX_N = 300;
const int MIN_NI = 0;
const int MAX_NI = 100;
const int rnd_test_n = 100;
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
dest.insert(dest.end(), orig.begin(), orig.end());
}
string output_tc(int n, const vector<int>& nums) {
ostringstream oss;
oss << n << endl;
for (int i = 0; i < nums.size(); i++) {
if (i != 0) oss << " ";
oss << nums[i];
}
oss << endl;
return oss.str();
}
vector<string> generate_sample_tests() {
vector<string> tests;
tests.push_back(output_tc(4, {3, 1, 5, 8}));
tests.push_back(output_tc(2, {1, 5}));
return tests;
}
vector<string> generate_manual_tests() {
vector<string> tests;
tests.push_back(output_tc(10, {1,1,1,1,1,1,1,1,1,0}));
tests.push_back(output_tc(10, {0,0,0,0,0,0,0,0,0,0}));
return tests;
}
string rnd_test(int i){
int min_n = MIN_N;
int max_n = MAX_N;
if(i<rnd_test_n / 3){
max_n = 5;
}
else if(i<rnd_test_n / 2){
max_n = 20;
}
int x = rnd.next(min_n, max_n);
vector<int> nums(x);
for (int i = 0; i < x; i++) {
nums[i] = rnd.next(MIN_NI, MAX_NI);
}
return(output_tc(x, nums));
}
vector<string> generate_random_tests() {
vector<string> tests;
for (int i = 0; i < rnd_test_n; i++){
tests.push_back(rnd_test(i));
}
return tests;
}
string extreme_test_1(){
vector<int> nums(300);
for (int i = 0; i < 300; i++) {
nums[i] = MAX_NI;
}
return(output_tc(MAX_N, nums));
}
string extreme_test_2(){
vector<int> nums(300);
for (int i = 0; i < 300; i++) {
nums[i] = (i % 100) + 1;
}
return(output_tc(MAX_N, nums));
}
vector<string> generate_extreme_tests(){
vector<string> tests;
tests.push_back(extreme_test_1());
tests.push_back(extreme_test_2());
return tests;
}
int main(int argc, char *argv[]) {
registerGen(argc, argv, 1);
vector<string> tests;
size_t test = 0;
append(tests, generate_sample_tests());
append(tests, generate_manual_tests());
append(tests, generate_random_tests());
append(tests, generate_extreme_tests());
for (const auto &t : tests) {
startTest(++test);
cout << t;
}
return 0;
}

1
estouro/src/script.sh Normal file
View File

@@ -0,0 +1 @@
generator

5963
estouro/src/testlib.h Normal file

File diff suppressed because it is too large Load Diff

18
estouro/src/validator.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
registerValidation(argc, argv);
int n = inf.readInt(1, 300, "n");
inf.readEoln();
for (int i = 0; i < n; i++) {
if (i != 0) inf.readSpace();
inf.readInt(0, 100, "nums[" + to_string(i) + "]");
}
inf.readEoln();
inf.readEof();
return 0;
}