이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 210;
const ll base = 29, inf = 1e18;
int n;
ll a, b, c, h[maxn], pw[maxn], dp[maxn][maxn];
string s;
void solve()
{
cin >> n >> s >> a >> b >> c;
s = "#" + s;
pw[0] = 1;
for (int i = 1; i <= n; i ++)
{
h[i] = h[i - 1] * base + (s[i] - 'a' + 1);
pw[i] = pw[i - 1] * base;
}
for (int i = 1; i <= n; i ++)
for (int j = i; j <= n; j ++)
dp[i][j] = inf;
for (int len = 1; len <= n; len ++)
for (int i = 1; i <= n - len + 1; i ++)
{
int j = i + len - 1;
dp[i][j] = dp[i][j - 1] + a;
for (int p = i; p <= j; p ++)
for (int k = p; k <= j; k ++)
{
ll clip_hash, clip_len = k - p + 1;
clip_hash = h[k] - h[p - 1] * pw[clip_len];
ll cost = dp[p][k] + b;
int pos = i;
while(pos <= j)
{
int to = pos + clip_len - 1;
if (to > j)
{
cost += (j - pos + 1) * a;
break;
}
if (h[to] - h[pos - 1] * pw[clip_len] == clip_hash)
{
cost = cost + c;
pos = pos + clip_len;
}
else
{
pos ++;
cost += a;
}
}
dp[i][j] = min(dp[i][j], cost);
}
}
cout << dp[1][n] << endl;
}
int main()
{
solve();
return 0;
}
# | 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... |