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>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 2e3 + 5;
const int mod = 1e9 + 7, oo = 1e18 + 7;
int n, a, b, c;
string s;
int dp[N][N];
void process(){
cin >> n >> s >> a >> b >> c;
s = '*' + s;
for(int i = 1; i <= n; i++) dp[i][i] = a;
for(int dist = 2; dist <= n; dist++){
for(int le = 1; le <= n; le++){
int ri = le + dist - 1;
if(ri > n) break;
dp[le][ri] = min(dp[le + 1][ri], dp[le][ri - 1]) + a;
for(int i = le; i < ri; i++){
int total = dp[le][i] + b + c, itr = i + 1;
while(itr <= ri){
string temp1 = s.substr(le, i - le + 1), temp2 = s.substr(itr, min(i - le + 1, ri - itr + 1));
if(temp1 != temp2){
itr++;
total += a;
}
else{
itr += (i - le + 1);
total += c;
}
}
dp[le][ri] = min(dp[le][ri], total);
}
// cout << le << " " << ri << " " << dp[le][ri] << "\n";
}
}
cout << dp[1][n] << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
//freopen("KEK.inp", "r", stdin);
//freopen("KEK.out", "w", stdout);
cin.tie(0);
process();
}
# | 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... |