Educational Codeforces Round 57D(DP,思维)

时间:2023-01-30 10:56:02

#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 思维 &plus; 区间dp

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

  2. Educational Codeforces Round 60 C 思维 &plus; 二分

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

  3. &lbrack;Educational Codeforces Round 63 &rsqb; D&period; Beautiful Array (思维&plus;DP)

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

  4. Educational Codeforces Round 53 E&period; Segment Sum&lpar;数位DP&rpar;

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

  5. &lbrack;Educational Codeforces Round 81 &lpar;Rated for Div&period; 2&rpar;&rsqb;E&period; Permutation Separation(线段树,思维,前缀和)

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

  6. Educational Codeforces Round 40 C&period; Matrix Walk&lpar; 思维&rpar;

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

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

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

  8. &lbrack;Educational Codeforces Round 16&rsqb;E&period; Generate a String

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

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. break与continue的区别

    break       在while.for.do...while.while循环中使用break语句退出当前循环,直接执行后面的代码. continue   的作用是仅仅跳过本次循环,而整个循环体继 ...

  2. Oracle笔记-表的管理

    3.1创建和管理表在Oracle表中使用的emp,dept,sal都是系统内建好的表,那么在SQL语法中同样支持了表的创建语句,要想创建表,则应先了解下Oracle中最常用的几种数据类型3.1.1常用 ...

  3. Creating a Navigation Drawer 创建一个导航侧边栏

    The navigation drawer is a panel that displays the app’s main navigation options on the left edge of ...

  4. android layout物业介绍

    android:id 为控件指定对应的ID android:text 指定控件其中显示的文字,须要注意的是,这里尽量使用strings.xml文件其中的字符串 android:gravity 指定Vi ...

  5. java中的分支结构 switch case的使用

    switch(A),括号中A的取值只能是整型或者可以转换为整型的数值类型,比如byte.short.int.char.string(jdk1.7后加入)还有枚举:需要强调的是:long是不能用在swi ...

  6. 开启Tomcat的manager页面访问

    如何进入Tomcat的manager页面 一张图解决! 找到conf目录下的tomcat-users.xml文件,打开. <role rolename="admin-gui" ...

  7. Linux&&num;160&semi;为linux&&num;160&semi;enterprises&&num;160&semi;6安装图形桌面教程

    为linux enterprises 6安装图形桌面教程 by:授客 QQ:1033553122 安装系统后发现没图形界面,安装Xwindow[为了避免权限不足,以root登录] 步骤1.启动图形界面 ...

  8. ubuntu 14&period;04 上配置vlc组播源

    VLC:  Video LAN多媒体播放器,是一个跨平台开源的软件,支持主流的编码格式MPEG-2.H.264等. (1)ubuntu上安装vlc: sudo  apt-get install vlc ...

  9. Codeforces Round &num;517 &lpar;Div&period; 2&comma; based on Technocup 2019 Elimination Round 2&rpar; D&period; Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  10. jdk自带的ThreadLocal和netty扩展的FastThreadLocal比较总结

    最近在分析一潜在内存泄露问题的时候,jmap出来中有很多的FastThreadLocalThread实例,看了下javadoc,如下: A special variant of ThreadLocal ...