#include<bits/stdc++.h>
using namespace std;
char s[100007];
long long a[100007];
long long dp[100007][4];
int main(){
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i=0;i<n;i++){
        dp[i][0]=dp[i-1][0];
        dp[i][1]=dp[i-1][1];
        dp[i][2]=dp[i-1][2];
        dp[i][3]=dp[i-1][3];
        if(s[i]=='h')
            dp[i][0]+=a[i],dp[i][1]=min(dp[i-1][0],dp[i-1][1]);//字符串中没有长度为1的子序列付出的代价
        else if(s[i]=='a')
            dp[i][1]+=a[i],dp[i][2]=min(dp[i-1][1],dp[i-1][2]);//字符串中没有长度为2的子序列付出的代价
        else if(s[i]=='r')
            dp[i][2]+=a[i],dp[i][3]=min(dp[i-1][2],dp[i-1][3]);//字符串中没有长度为3的子序列付出的代价
        else if(s[i]=='d')
            dp[i][3]+=a[i];//字符串中没有hard付出的代价
    }
    long long ans=1e18;
    for(int i=0;i<4;i++)
        ans=min(ans,dp[n-1][i]);
    printf("%lld",ans);
    return 0;
}

Educational Codeforces Round 57D(DP,思维)的更多相关文章

  1. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  2. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  3. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  4. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  5. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

  6. Educational Codeforces Round 40 C. Matrix Walk( 思维)

    Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...

  7. Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)

    Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...

  8. Educational Codeforces Round 128 (Rated for Div. 2) A-C+E

    Educational Codeforces Round 128 (Rated for Div. 2) A-C+E A 题目 https://codeforces.com/contest/1680/p ...

  9. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

随机推荐

  1. 机器学习(二十四)— 偏差Bias 与方差Variance

    1.首先 Error = Bias + Variance  Error反映的是整个模型的准确度, Bias反映的是模型在样本上的输出与真实值之间的误差,即模型本身的精准度, Variance反映的是模 ...

  2. ashx页面缓存

    当用户访问页面时,整个页面将会被服务器保存在内存中,这样就对页面进行了缓存.当用户再次访问该页,页面不会再次执行数据操作,页面首先会检查服务器中是否存在缓存,如果缓存存在,则直接从缓存中获取页面信息, ...

  3. Linux-MySQL主从配置

    1. MySQL主从原理以及应用场景MySQL的Replication原理非常简单,总结一下:每个从仅可以设置一个主.主在执行sql之后,记录二进制log文件(bin-log).从连接主,并从主获取b ...

  4. 【leetcode刷题笔记】Sqrt(x)

    Implement int sqrt(int x). Compute and return the square root of x. 题解:二分的方法,从0,1,2.....x搜索sqrt(x)的值 ...

  5. fswebcam 获取图片

    /************************************************************************* * fswebcam 获取图片 * 说明: * 通 ...

  6. ffmpeg混音(将多个声音合成一个)命令

    ffmpeg命令中可以使用filter amix实现这个功能. 官方文档 http://ffmpeg.org/ffmpeg-filters.html 6.8 amix Mixes multiple a ...

  7. 【Lintcode】363.Trapping Rain Water

    题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...

  8. 迁移学习-微调(fine-tune)的注意事项:

    选取微调形式的两个重要因素:新数据集的大小(size)和相似性(与预训练的数据集相比).牢记卷积网络在提取特征时,前面的层所提取的更具一般性,后面的层更加具体,更倾向于原始的数据集(more orig ...

  9. [转]基于phantomJS实现web性能监控

    1.web性能监控背景描述 上期分享的<Web性能监控自动化探索之路–初识WebPageTest>从依赖webpagetest的角度给出了做性能日常检查的方案,但由于依赖结构相对复杂我们需 ...

  10. Boost库之asio io_service以及run、run_one、poll、poll_one区别

    一.io_service的作用 io_servie 实现了一个任务队列,这里的任务就是void(void)的函数.Io_servie最常用的两个接口是post和run,post向任务队列中投递任务,r ...