This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, a, b, c;
std::string s;
std::cin >> n >> s >> a >> b >> c;
std::vector<std::vector<ll>> dp(n + 1, std::vector<ll>(n + 1));
// dp[i][j] = the minimum cost to match n - i a's if there are j a's in the
// clipboard
/*
dp[i][j] = min{
dp[i + 1][j] + a,
dp[i + j][j] + c (j != 0),
dp[0][i] + b (i > j)
}
*/
for (ll j = n - 1; j >= 0; --j) {
for (ll i = n - 1; i >= 0; --i) {
dp[i][j] = dp[i + 1][j] + a;
if (j != 0 and i + j <= n) {
dp[i][j] = std::min(dp[i][j], dp[i + j][j] + c);
}
if (i > j) {
dp[i][j] = std::min(dp[i][j], dp[0][i] + b);
}
}
}
std::cout << dp[0][0] << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |