跳到正文

个人记录

划分字符串

lixin_hoshino约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年12月13日
收录
2026年1月2日
更新
2026年8月27日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.tie(0);
    int n;string zhun;cin >> n >> zhun;int shu[26];
    for(int i = 1;i<=n && i<=26;i++)
    {
        cin >> shu[i];
    }
    int end_ = 0;
    vector<long long> dp(n+1,0);
    for(int i = 1;i<=n;i++)
    {
        dp[i] = dp[i-1]+shu[1];
        int len = 2;
        for(int j = i-2;j >= end_;j--)
        {
            if(zhun[j] != zhun[i-1])
            {
                dp[i] = max(dp[i],dp[i-len]+shu[len]);
            }
            else{
                end_ = j+1;
            }
            len++;
        }
    }
    cout << dp[n];
}
原文