Educational Codeforces Round 57D(DP,思维)
#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,思维)的更多相关文章
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- [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 ...
- Educational Codeforces Round 53 E. Segment Sum(数位DP)
Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...
- [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...
- 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 ...
- 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 ...
- 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 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
随机推荐
- linux没有eth0
1.创建ifcfg-eth0 touch /etc/sysconfig/network-scripts/ifcfg-eth0 2.配置ifcfg-eth0 DEVICE=eth0 HWADDR=:0c ...
- HTTP-接触
[HTTP]http是基于TCP/IP协议的应用层协议,他不涉及数据包(packet)传输,主要规定了客户端和服务器之间的通信格式,默认端口是80端口. 不同版本http协议里的相关概念[Conten ...
- Unity3D之Mesh(五)绘制圆
前言: Unity3D中Mesh的基本单位是三角形,而圆形就是由许许多多的三角形组成的.那么我们就知道了绘制圆形的Mesh需要两个变量:圆的半径 以及分割数: 一.实现过程 基本过程与之前的类似,最 ...
- MySQL--Basic(一)
停止与启动服务命令: net stop mysql net start mysql 修改MySQL提示符: mysql>prompt \u@\h \d> MySQL语句规范: 关键字与函数 ...
- Struts2 - ModelDriven 拦截器、Preparable 拦截器
开篇:拦截器在Struts中的作用 在我们的web.xml中,我们配置了一个过滤器,实现将所有请求交付StrutsPrepareAndExecuteFilter类.一旦接受到任意action的请求,该 ...
- 【leetcode刷题笔记】Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...
- Skype SILK vs. iLBC vs. Speex
对比一下这三种VOIP语音算法的特点: 1 参数与特征 2 SILK性能 关于iLBC和Speex的性能可以参考以前写的文章. 3 关于VOIP一些观点(仅代表个人观点) 1) Skype 辛苦三年 ...
- hdu2196 Computer待续
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #i ...
- ACM学习历程—UESTC 1226 Huatuo's Medicine(数学)(2015CCPC L)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. ...
- uoj problem 12 猜数
题目大意 每次询问给出g,l,有\(a*b = g*l = n\),且\(a,b\)均为\(g\)的倍数.求\(a+b\)的最小值和\(a-b\)的最大值. 题解 因为\(a,b\)均为\(g\)的倍 ...