比赛 |
2025暑期集训第6场 |
评测结果 |
AAAAAAAAAAAAAAAA |
题目名称 |
Moortal Cowmbat |
最终得分 |
100 |
用户昵称 |
xxz |
运行时间 |
0.478 s |
代码语言 |
C++ |
内存使用 |
26.56 MiB |
提交时间 |
2025-07-12 11:37:53 |
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,d[50][50],sum[100005][50],dp1[100005],dp2[50];
string s;
void read(int &x) {bool neg = false;x = 0;char ch = 0;while (ch < '0' || ch > '9') {if (ch == '-') neg = true;ch = getchar();}if (neg) {while (ch >= '0' && ch <= '9') {x = x * 10 + ('0' - ch);ch = getchar();}} else {while (ch >= '0' && ch <= '9') {x = x * 10 + (ch - '0');ch = getchar();}}return;}
signed main(){
freopen("cowmbat.in","r",stdin);freopen("cowmbat.out","w",stdout);
read(n);read(m);read(k);
cin>>s;
s=' '+s;
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
read(d[i][j]);
for(int o=1;o<=m;o++)
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
d[i][j]=min(d[i][j],d[i][o]+d[o][j]);
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
sum[j][i]=sum[j-1][i]+d[s[j]-'a'+1][i];
memset(dp1,0x3f,sizeof(dp1));
dp1[0]=0;
for(int j=1;j<=m;j++)dp2[j]=0;
for(int i=1;i<=n;i++){
if(i>=k){
for(int j=1;j<=m;j++)dp2[j]=min(dp2[j], dp1[i-k]-sum[i-k][j]);
for(int j=1;j<=m;j++)dp1[i]=min(dp1[i], dp2[j]+sum[i][j]);
}
}
cout<<dp1[n];
return 0;
}